Explorar o código

feat: 目标检测和可见光转红外完善

WANGKANG hai 5 meses
pai
achega
27489514da

+ 43 - 36
taais-modules/taais-biz/src/main/java/com/taais/biz/service/impl/TargetDetectionServiceImpl.java

@@ -12,7 +12,6 @@ import com.taais.biz.constant.BizConstant;
 import com.taais.biz.domain.*;
 import com.taais.biz.domain.bo.TargetDetectionBo;
 import com.taais.biz.domain.vo.AlgorithmConfigTrackVo;
-import com.taais.biz.domain.vo.AlgorithmModelTrackVo;
 import com.taais.biz.domain.vo.StartTaskConfig;
 import com.taais.biz.domain.vo.TargetDetectionVo;
 import com.taais.biz.mapper.TargetDetectionMapper;
@@ -23,7 +22,6 @@ import com.taais.common.core.constant.Constants;
 import com.taais.common.core.core.domain.CommonResult;
 import com.taais.common.core.core.page.PageResult;
 import com.taais.common.core.utils.MapstructUtils;
-import com.taais.common.core.utils.StringUtils;
 import com.taais.common.json.utils.JsonUtils;
 import com.taais.common.orm.core.page.PageQuery;
 import com.taais.common.orm.core.service.impl.BaseServiceImpl;
@@ -50,7 +48,8 @@ import java.util.*;
 import static com.taais.biz.constant.BizConstant.VideoStatus.NOT_START;
 import static com.taais.biz.domain.table.TargetDetectionTableDef.TARGET_DETECTION;
 import static com.taais.biz.service.impl.ToInfraredServiceImpl.*;
-import static com.taais.biz.service.impl.VideoStableServiceImpl.*;
+import static com.taais.biz.service.impl.VideoStableServiceImpl.makeDir;
+import static com.taais.biz.service.impl.VideoStableServiceImpl.sendPostMsg;
 
 /**
  * 目标检测Service业务层处理
@@ -204,46 +203,49 @@ public class TargetDetectionServiceImpl extends BaseServiceImpl<TargetDetectionM
         Map<String, Object> algorithmParameters = getAlgorithmParameters(algorithmConfig.getParameters(), entityBo.getOtherParams());
 
         // 步骤4. 构造可以直接传给前端的map数据结构
+        Map<String, Object> result = new HashMap<>();
 
-        Map<String, Object> result = getCommonResultParams(entity.getId(), ossEntity);
+        result.put("biz_id", entity.getId());
+        result.put("biz_type", BizConstant.BizType.TARGET_DETECTION);
 
-        if (algorithmConfig.getType().equals(BizConstant.AlgorithmType.REASONING)) {
+        if (algorithmConfig.getType().equals(BizConstant.AlgorithmType.TRAIN)) {
+            String source_dir = getTrainInputPath(ossEntity);
+            String result_dir = getTrainOutputPath(entity, ossEntity);
+            String log_path = getLogFilePath(result_dir, entity.getId(), BizConstant.TARGET_DETECTION_SUFFIX);
+            result.put("source_dir", source_dir);
+            result.put("result_dir", result_dir);
+            result.put("log_path", log_path);
+        } else if (algorithmConfig.getType().equals(BizConstant.AlgorithmType.REASONING)) {
+            String source_dir = getPredictInputPath(ossEntity);
+            String result_dir = getPredictOutputPath(entity, ossEntity);
+            String log_path = getLogFilePath(result_dir, entity.getId(), BizConstant.TARGET_DETECTION_SUFFIX);
             String model_path = getModelPath(entity);
+            result.put("source_dir", source_dir);
+            result.put("result_dir", result_dir);
+            result.put("log_path", log_path);
             result.put("model_path", model_path);
+        } else {
+            throw new RuntimeException("算法类型错误");
         }
+
         result.put("otherParams", algorithmParameters);
 
         entity.setInputPath((String) result.get("source_dir"));
         entity.setOutputPath((String) result.get("result_dir"));
         entity.setLogPath((String) result.get("log_path"));
-
         // 步骤 5. 将算法参数map序列化为json字符串,保存到数据库中
         entity.setAlgorithmParameters(JsonUtils.toJsonString(result));
 
-//        makeDir(entity.getInputPath());
-//        makeDir(entity.getOutputPath());
-//
-//        File file = new File(entity.getInputPath());
-//        if (!file.exists()) {
-//            String resourcePath = getResourcePath(ossService.getById(entity.getInputOssId()));
-//            ZipUtils.unzip(resourcePath, entity.getInputPath());
-//        }
+        makeDir(entity.getInputPath());
+        makeDir(entity.getOutputPath());
 
-        return entity;
-    }
-
-    private Map<String, Object> getCommonResultParams(Long id, SysOssVo ossEntity) {
-        Map<String, Object> result = new HashMap<>();
-        String source_dir = getTrainInputPath(ossEntity);
-        String result_dir = getTrainOutputPath(id, ossEntity);
-        String log_path = getLogFilePath(result_dir, id, BizConstant.TARGET_DETECTION_SUFFIX);
+        File file = new File(entity.getInputPath());
+        if (!file.exists()) {
+            String resourcePath = getResourcePath(ossService.getById(entity.getInputOssId()));
+            ZipUtils.unzip(resourcePath, entity.getInputPath());
+        }
 
-        result.put("biz_id", id);
-        result.put("biz_type", BizConstant.BizType.TARGET_DETECTION);
-        result.put("source_dir", source_dir);
-        result.put("result_dir", result_dir);
-        result.put("log_path", log_path);
-        return result;
+        return entity;
     }
 
     /**
@@ -283,23 +285,28 @@ public class TargetDetectionServiceImpl extends BaseServiceImpl<TargetDetectionM
     }
 
     public String getTrainInputPath(SysOssVo ossEntity) {
-        // todo
-        return null;
+        return getUnZipDirPath(ossEntity);
     }
 
-    public String getTrainOutputPath(Long id, SysOssVo ossEntity) {
-        // todo
-        return null;
+    public String getTrainOutputPath(TargetDetection entity, SysOssVo ossEntity) {
+        String resourcePath = getResourcePath(ossEntity);
+        Path path = Paths.get(resourcePath);
+        Path outputPath = path.resolveSibling(entity.getId().toString() + BizConstant.TARGET_DETECTION_SUFFIX);
+        return outputPath.toString();
     }
 
+
     public String getPredictInputPath(SysOssVo ossEntity) {
         // todo
-        return null;
+        return getUnZipDirPath(ossEntity);
     }
 
     public String getPredictOutputPath(TargetDetection entity, SysOssVo ossEntity) {
         // todo
-        return null;
+        String resourcePath = getResourcePath(ossEntity);
+        Path path = Paths.get(resourcePath);
+        Path outputPath = path.resolveSibling(entity.getId().toString() + BizConstant.TARGET_DETECTION_SUFFIX);
+        return outputPath.toString();
     }
 
     private String getModelPath(TargetDetection entity) {
@@ -309,7 +316,7 @@ public class TargetDetectionServiceImpl extends BaseServiceImpl<TargetDetectionM
 
     @Override
     public CommonResult start(Long id) {
-       TargetDetection entity = getById(id);
+        TargetDetection entity = getById(id);
         entity.setStartTime(new Date());
 
         AlgorithmConfigTrack algorithmConfigTrack = algorithmConfigTrackService.getById(entity.getAlgorithmId());

+ 24 - 19
taais-modules/taais-biz/src/main/java/com/taais/biz/service/impl/ToInfraredServiceImpl.java

@@ -232,19 +232,38 @@ public class ToInfraredServiceImpl extends BaseServiceImpl<ToInfraredMapper, ToI
         Map<String, Object> algorithmParameters = getAlgorithmParameters(algorithmConfig.getParameters(), entityBo.getOtherParams());
 
         // 步骤4. 构造可以直接传给前端的map数据结构
+        Map<String, Object> result = new HashMap<>();
 
-        Map<String, Object> result = getCommonResultParams(entity.getId(), ossEntity);
+        result.put("biz_id", entity.getId());
+        result.put("biz_type", BizConstant.BizType.TO_INFRARED);
 
-        if (algorithmConfig.getType().equals(BizConstant.AlgorithmType.REASONING)) {
+        if (algorithmConfig.getType().equals(BizConstant.AlgorithmType.TRAIN)) {
+            String source_dir = getTrainInputPath(ossEntity);
+            String result_dir = getTrainOutputPath(entity, ossEntity);
+            String log_path = getLogFilePath(result_dir, entity.getId(), BizConstant.TO_INFRARED_SUFFIX);
+            result.put("source_dir", source_dir);
+            result.put("result_dir", result_dir);
+            result.put("log_path", log_path);
+        }
+        else if (algorithmConfig.getType().equals(BizConstant.AlgorithmType.REASONING)) {
+            String source_dir = getPredictInputPath(ossEntity);
+            String result_dir = getPredictOutputPath(entity, ossEntity);
+            String log_path = getLogFilePath(result_dir, entity.getId(), BizConstant.TO_INFRARED_SUFFIX);
             String model_path = getModelPath(entity);
+            result.put("source_dir", source_dir);
+            result.put("result_dir", result_dir);
+            result.put("log_path", log_path);
             result.put("model_path", model_path);
         }
+        else {
+            throw new RuntimeException("算法类型错误");
+        }
+
         result.put("otherParams", algorithmParameters);
 
         entity.setInputPath((String) result.get("source_dir"));
         entity.setOutputPath((String) result.get("result_dir"));
         entity.setLogPath((String) result.get("log_path"));
-
         // 步骤 5. 将算法参数map序列化为json字符串,保存到数据库中
         entity.setAlgorithmParameters(JsonUtils.toJsonString(result));
 
@@ -260,20 +279,6 @@ public class ToInfraredServiceImpl extends BaseServiceImpl<ToInfraredMapper, ToI
         return entity;
     }
 
-    private Map<String, Object> getCommonResultParams(Long id, SysOssVo ossEntity) {
-        Map<String, Object> result = new HashMap<>();
-        String source_dir = getTrainInputPath(ossEntity);
-        String result_dir = getTrainOutputPath(id, ossEntity);
-        String log_path = getLogFilePath(result_dir, id, BizConstant.TO_INFRARED_SUFFIX);
-
-        result.put("biz_id", id);
-        result.put("biz_type", BizConstant.BizType.TO_INFRARED);
-        result.put("source_dir", source_dir);
-        result.put("result_dir", result_dir);
-        result.put("log_path", log_path);
-        return result;
-    }
-
     /**
      * 修改可见光转红外
      *
@@ -331,10 +336,10 @@ public class ToInfraredServiceImpl extends BaseServiceImpl<ToInfraredMapper, ToI
         return getUnZipDirPath(ossEntity);
     }
 
-    public String getTrainOutputPath(Long id, SysOssVo ossEntity) {
+    public String getTrainOutputPath(ToInfrared entity, SysOssVo ossEntity) {
         String resourcePath = getResourcePath(ossEntity);
         Path path = Paths.get(resourcePath);
-        Path outputPath = path.resolveSibling(id.toString() + BizConstant.TO_INFRARED_SUFFIX);
+        Path outputPath = path.resolveSibling(entity.getId().toString() + BizConstant.TO_INFRARED_SUFFIX);
         return outputPath.toString();
     }