|
@@ -55,10 +55,11 @@ import static com.taais.biz.service.impl.VideoStableServiceImpl.sendPostMsg;
|
|
|
* 目标检测Service业务层处理
|
|
|
*
|
|
|
* @author wangkang
|
|
|
- * 2024-09-29
|
|
|
+ * 2024-09-29
|
|
|
*/
|
|
|
@Service
|
|
|
-public class TargetDetectionServiceImpl extends BaseServiceImpl<TargetDetectionMapper, TargetDetection> implements ITargetDetectionService {
|
|
|
+public class TargetDetectionServiceImpl extends BaseServiceImpl<TargetDetectionMapper, TargetDetection>
|
|
|
+ implements ITargetDetectionService {
|
|
|
@Value("${server.port}")
|
|
|
public static String port;
|
|
|
|
|
@@ -207,13 +208,14 @@ public class TargetDetectionServiceImpl extends BaseServiceImpl<TargetDetectionM
|
|
|
throw new RuntimeException("算法配置参数为空");
|
|
|
}
|
|
|
|
|
|
- Map<String, Object> algorithmParameters = getAlgorithmParameters(algorithmConfig.getParameters(), entityBo.getOtherParams());
|
|
|
+ Map<String, Object> algorithmParameters = getAlgorithmParameters(algorithmConfig.getParameters(),
|
|
|
+ entityBo.getOtherParams());
|
|
|
|
|
|
// 步骤4. 构造可以直接传给前端的map数据结构
|
|
|
Map<String, Object> result = new HashMap<>();
|
|
|
|
|
|
- result.put("biz_id", entity.getId());
|
|
|
- result.put("biz_type", BizConstant.BizType.TARGET_DETECTION);
|
|
|
+ result.put("bizId", entity.getId());
|
|
|
+ result.put("bizType", BizConstant.BizType.TARGET_DETECTION);
|
|
|
|
|
|
if (algorithmConfig.getType().equals(BizConstant.AlgorithmType.TRAIN)) {
|
|
|
String source_dir = getTrainInputPath(ossEntity);
|
|
@@ -292,7 +294,21 @@ public class TargetDetectionServiceImpl extends BaseServiceImpl<TargetDetectionM
|
|
|
}
|
|
|
|
|
|
public String getTrainInputPath(SysOssVo ossEntity) {
|
|
|
- return getUnZipDirPath(ossEntity);
|
|
|
+ String unzipPath = getUnZipDirPath(ossEntity);
|
|
|
+ File file = new File(unzipPath);
|
|
|
+ if (!file.exists()) {
|
|
|
+ throw new RuntimeException("文件路径不存在");
|
|
|
+ }
|
|
|
+ File[] listFiles = file.listFiles();
|
|
|
+ if (listFiles == null || listFiles.length == 0) {
|
|
|
+ throw new RuntimeException("文件路径为空!");
|
|
|
+ }
|
|
|
+ for (File f : listFiles) {
|
|
|
+ if (f.isDirectory()) { // 找到第一个目录
|
|
|
+ return f.getAbsolutePath();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
}
|
|
|
|
|
|
public String getTrainOutputPath(TargetDetection entity, SysOssVo ossEntity) {
|
|
@@ -302,7 +318,6 @@ public class TargetDetectionServiceImpl extends BaseServiceImpl<TargetDetectionM
|
|
|
return outputPath.toString();
|
|
|
}
|
|
|
|
|
|
-
|
|
|
public String getPredictInputPath(SysOssVo ossEntity) {
|
|
|
// todo
|
|
|
return getUnZipDirPath(ossEntity);
|
|
@@ -378,14 +393,17 @@ public class TargetDetectionServiceImpl extends BaseServiceImpl<TargetDetectionM
|
|
|
updateById(entity);
|
|
|
|
|
|
AlgorithmModelTrack algorithmModelTrack = algorithmModelTrackService.getById(entity.getAlgorithmModelId());
|
|
|
- algorithmModelTrack.setModelStatus("200".equals(status) ? BizConstant.ModelStatus.END : BizConstant.ModelStatus.FAILED);
|
|
|
+ algorithmModelTrack
|
|
|
+ .setModelStatus("200".equals(status) ? BizConstant.ModelStatus.END : BizConstant.ModelStatus.FAILED);
|
|
|
|
|
|
- AlgorithmConfigTrack algorithmConfigTrack = algorithmConfigTrackService.getById(algorithmModelTrack.getAlgorithmId());
|
|
|
+ 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"));
|
|
|
+ algorithmModelTrack.setModelAddress(entity.getOutputPath() + File.separator
|
|
|
+ + ((HashMap<String, String>) parse.get("dataset")).get("classes"));
|
|
|
|
|
|
System.out.println(parse.get("dataset"));
|
|
|
algorithmModelTrackService.updateById(algorithmModelTrack);
|
|
@@ -395,24 +413,24 @@ public class TargetDetectionServiceImpl extends BaseServiceImpl<TargetDetectionM
|
|
|
* 这里有很多需要做的: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();
|
|
|
- }
|
|
|
- }
|
|
|
- */
|
|
|
+ * 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();
|
|
|
+ * }
|
|
|
+ * }
|
|
|
+ */
|
|
|
WebSocketUtils.publishAll("refresh");
|
|
|
return CommonResult.success();
|
|
|
}
|
|
@@ -441,7 +459,9 @@ public class TargetDetectionServiceImpl extends BaseServiceImpl<TargetDetectionM
|
|
|
}
|
|
|
|
|
|
org.springframework.core.io.Resource resource = new FileSystemResource(file);
|
|
|
- return ResponseEntity.ok().header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + file.getName() + "\"").header(HttpHeaders.CONTENT_TYPE, "application/octet-stream").body(resource);
|
|
|
+ return ResponseEntity.ok()
|
|
|
+ .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + file.getName() + "\"")
|
|
|
+ .header(HttpHeaders.CONTENT_TYPE, "application/octet-stream").body(resource);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -480,7 +500,8 @@ public class TargetDetectionServiceImpl extends BaseServiceImpl<TargetDetectionM
|
|
|
tmp.put("path", filePath);
|
|
|
// todo 获取真正的url
|
|
|
// http://localhost:9090/profile/upload/2024/10/27/1_1729404909511_20241027153840A001.zip
|
|
|
- String url = "http://localhost:" + port + Constants.RESOURCE_PREFIX + filePath.substring(TaaisConfig.getProfile().length());
|
|
|
+ String url = "http://localhost:" + port + Constants.RESOURCE_PREFIX
|
|
|
+ + filePath.substring(TaaisConfig.getProfile().length());
|
|
|
url = url.replaceAll("\\\\", "/"); // windows
|
|
|
tmp.put("url", url);
|
|
|
|