Bladeren bron

feat: 目标检测预测接口对接完成

WANGKANG 8 maanden geleden
bovenliggende
commit
61867c65b2

+ 10 - 10
taais-modules/taais-biz/src/main/java/com/taais/biz/component/ScheduledTasks.java

@@ -26,14 +26,14 @@ public class ScheduledTasks {
     //    log.info("ScheduledTasks.runTask end");
     //}
 
-    @Scheduled(fixedRate = 30000)
-    public void taskRun() {
-        try {
-            log.info("ScheduledTasks.taskRun start");
-            targetIdentificationTaskService.taskRun();
-            log.info("ScheduledTasks.taskRun end");
-        } catch (Exception e) {
-            log.error("ScheduledTasks.taskRun error", e);
-        }
-    }
+//    @Scheduled(fixedRate = 30000)
+//    public void taskRun() {
+//        try {
+//            log.info("ScheduledTasks.taskRun start");
+//            targetIdentificationTaskService.taskRun();
+//            log.info("ScheduledTasks.taskRun end");
+//        } catch (Exception e) {
+//            log.error("ScheduledTasks.taskRun error", e);
+//        }
+//    }
 }

+ 18 - 2
taais-modules/taais-biz/src/main/java/com/taais/biz/service/impl/AlgorithmModelTrackServiceImpl.java

@@ -1,5 +1,6 @@
 package com.taais.biz.service.impl;
 
+import java.io.File;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashMap;
@@ -37,6 +38,7 @@ import com.taais.biz.service.IAlgorithmModelTrackService;
 
 import static com.taais.biz.domain.table.AlgorithmModelTrackTableDef.ALGORITHM_MODEL_TRACK;
 import static com.taais.biz.constant.BizConstant.AlgorithmType;
+import static com.taais.biz.utils.ZipUtils.unzip;
 
 /**
  * 算法模型配置Service业务层处理
@@ -149,7 +151,7 @@ public class AlgorithmModelTrackServiceImpl extends BaseServiceImpl<AlgorithmMod
     public CommonResult<String> insert(AlgorithmModelTrackBo algorithmModelTrackBo) {
         AlgorithmConfigTrackVo algorithmConfigTrackVo = algorithmConfigTrackService.selectById(algorithmModelTrackBo.getAlgorithmId());
         if (algorithmConfigTrackVo.getType().equals(AlgorithmType.REASONING) && ObjectUtil.isEmpty(algorithmModelTrackBo.getModelInputOssId())) {
-            return CommonResult.fail("预测算法必须上传模型输入文件");
+            return CommonResult.fail("预测算法必须上传模型文件");
         }
 
         AlgorithmModelTrack algorithmModelTrack = MapstructUtils.convert(algorithmModelTrackBo, AlgorithmModelTrack.class);
@@ -161,13 +163,27 @@ public class AlgorithmModelTrackServiceImpl extends BaseServiceImpl<AlgorithmMod
             String filePath = inputOssEntity.getFileName();
             String localPath = TaaisConfig.getProfile();
             resourcePath = localPath + StringUtils.substringAfter(filePath, Constants.RESOURCE_PREFIX);
-            algorithmModelTrack.setModelAddress(resourcePath);
+
+
+            if (resourcePath.endsWith(".zip")) {
+                String modelAddress = resourcePath.substring(0, resourcePath.lastIndexOf("."));
+                File file = new File(modelAddress);
+                if (!file.exists()) {
+                    unzip(resourcePath, modelAddress);
+                }
+                algorithmModelTrack.setModelAddress(modelAddress);
+            } else if (resourcePath.endsWith(".pt")) {
+                algorithmModelTrack.setModelAddress(resourcePath);
+            } else {
+                return CommonResult.fail("模型格式不正确,请上传.zip或.pt文件");
+            }
         } else {
             // String localPath = TaaisConfig.getUploadPath();
             // String path = DateUtils.datePath() + "/" + IdUtil.fastSimpleUUID();
             // resourcePath = localPath + "/" + path + ".pt";
             // 本来这里是默认整一个虚拟模型地址,后面发现不合适便去掉了
         }
+
         if (AlgorithmType.REASONING.equals(algorithmConfigTrackVo.getType()) || AlgorithmType.TEST.equals(algorithmConfigTrackVo.getType())) {
             algorithmModelTrack.setModelStatus(BizConstant.ModelStatus.END);
         } else if (AlgorithmType.TRAIN.equals(algorithmConfigTrackVo.getType())) {

+ 42 - 1
taais-modules/taais-biz/src/main/java/com/taais/biz/service/impl/TargetDetectionServiceImpl.java

@@ -6,6 +6,7 @@ import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.Arrays;
 import java.util.Date;
+import java.util.HashMap;
 import java.util.List;
 
 import cn.hutool.core.util.ObjectUtil;
@@ -47,6 +48,8 @@ import static com.taais.biz.domain.table.TargetDetectionTableDef.TARGET_DETECTIO
 import static com.taais.biz.service.impl.VideoStableServiceImpl.*;
 import static com.taais.biz.service.impl.VideoStableServiceImpl.sendPostMsg;
 
+import com.alibaba.fastjson2.JSON;
+
 /**
  * 目标检测Service业务层处理
  *
@@ -270,7 +273,8 @@ public class TargetDetectionServiceImpl extends BaseServiceImpl<TargetDetectionM
         startToInfraredTask.setResult_dir(entity.getOutputPath());
 
         if (BizConstant.AlgorithmType.REASONING.equals(algorithmConfigTrack.getType())) {
-            startToInfraredTask.setModel_path(algorithmModelTrack.getModelAddress());
+            String modelPath = algorithmModelTrack.getModelAddress() + File.separator + algorithmModelTrack.getModelName();
+            startToInfraredTask.setModel_path(modelPath);
         }
 
 
@@ -319,6 +323,43 @@ public class TargetDetectionServiceImpl extends BaseServiceImpl<TargetDetectionM
             entity.setCostSecond(null);
         }
         updateById(entity);
+
+        AlgorithmModelTrack algorithmModelTrack = algorithmModelTrackService.getById(entity.getAlgorithmModelId());
+        algorithmModelTrack.setModelStatus("200".equals(status) ? BizConstant.ModelStatus.END : BizConstant.ModelStatus.FAILED);
+
+        AlgorithmConfigTrack algorithmConfigTrack = algorithmConfigTrackService.getById(algorithmModelTrack.getAlgorithmId());
+        String params =  algorithmConfigTrack.getParameterConfig();
+        HashMap<String, Object> parse = (HashMap<String, Object>) JSON.parse((params));
+
+        if("200".equals(status) && ObjectUtil.isNull(algorithmModelTrack.getModelAddress())) {
+            algorithmModelTrack.setModelAddress(entity.getOutputPath() + File.separator + ((HashMap<String, String>)parse.get("dataset")).get("classes"));
+
+            System.out.println(parse.get("dataset"));
+            algorithmModelTrackService.updateById(algorithmModelTrack);
+        }
+
+        /*
+         * 这里有很多需要做的:1. 保存所有模型到oss 2. 模型文件保存到算法模型配置表中
+         */
+        /*
+        Path resultsPath = Paths.get(entity.getInputPath());
+        Path modelPath = resultsPath.resolve(BizConstant.MODEL_PATH);
+
+        File modelDir = new File(modelPath.toString());
+
+        if(!modelDir.exists() || !modelDir.isDirectory()) {
+            return CommonResult.fail("模型文件不存在");
+        }
+
+        for (File f : modelDir.listFiles()) {
+            if (f.isFile() && f.getName().endsWith(BizConstant.MODEL_SUFFIX)) {
+                SysOssVo upload = ossService.upload(f);
+                AlgorithmModelTrack algorithmModelTrack = new AlgorithmModelTrack();
+                algorithmModelTrack.set
+                algorithmModelTrackService.insert();
+            }
+        }
+        */
         return CommonResult.success();
     }