|
@@ -2,9 +2,7 @@ package com.taais.biz.service.impl;
|
|
|
|
|
|
import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
-import java.util.Arrays;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Random;
|
|
|
+import java.util.*;
|
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.esotericsoftware.minlog.Log;
|
|
@@ -35,6 +33,8 @@ import com.taais.biz.domain.TargetIdentificationTask;
|
|
|
import com.taais.biz.domain.bo.TargetIdentificationTaskBo;
|
|
|
import com.taais.biz.domain.vo.TargetIdentificationTaskVo;
|
|
|
|
|
|
+import javax.security.auth.Subject;
|
|
|
+
|
|
|
import static com.taais.biz.domain.table.TargetIdentificationTaskTableDef.TARGET_IDENTIFICATION_TASK;
|
|
|
|
|
|
/**
|
|
@@ -49,9 +49,9 @@ public class TargetIdentificationTaskServiceImpl extends BaseServiceImpl<TargetI
|
|
|
private TargetIdentificationTaskMapper targetIdentificationTaskMapper;
|
|
|
|
|
|
@Resource
|
|
|
- private ITargetIdentificationSubtaskService subtaskService;
|
|
|
+ private TargetIdentificationSubtaskServiceImpl subtaskService;
|
|
|
@Resource
|
|
|
- private ITargetIdentificationSubtaskDetailsService subtaskDetailsService;
|
|
|
+ private TargetIdentificationSubtaskDetailsServiceImpl subtaskDetailsService;
|
|
|
|
|
|
@Resource
|
|
|
private IAlgorithmTaskConfigurationService algorithmTaskConfigurationService;
|
|
@@ -170,11 +170,15 @@ public class TargetIdentificationTaskServiceImpl extends BaseServiceImpl<TargetI
|
|
|
|
|
|
@Override
|
|
|
public void taskRun() {
|
|
|
- TargetIdentificationTask task = targetIdentificationTaskMapper.getAvailableTask();
|
|
|
- if (task == null) {
|
|
|
- return;
|
|
|
+ Long id = subtaskDetailsService.getAvailableTask();
|
|
|
+ if (id != null) {
|
|
|
+ subtaskService.executeOneTask(id);
|
|
|
}
|
|
|
- subtaskService.taskRun(task);
|
|
|
+ //TargetIdentificationTask task = targetIdentificationTaskMapper.getAvailableTask();
|
|
|
+ //if (task == null) {
|
|
|
+ // return;
|
|
|
+ //}
|
|
|
+ //subtaskService.taskRun(task);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -195,22 +199,23 @@ public class TargetIdentificationTaskServiceImpl extends BaseServiceImpl<TargetI
|
|
|
taskBo.setId(task.getId());
|
|
|
System.out.println("taskBo is: " + taskBo);
|
|
|
|
|
|
+ Map<String, String> records = null;
|
|
|
// 创建训练子任务
|
|
|
if(taskDto.getTaskItemList().contains(CreateTargetIdentificationTaskDto.TASK_TYPE_SINGLE_DATA_AND_MORE_ALGORITHM)){
|
|
|
- createTrainTask(taskBo.getId(),taskDto);
|
|
|
+ records = createTrainTask(taskBo.getId(),taskDto);
|
|
|
}
|
|
|
// 创建测试子任务
|
|
|
if (taskDto.getTaskItemList().contains(CreateTargetIdentificationTaskDto.TASK_TYPE_SINGLE_DATA_AND_MORE_ALGORITHM)){
|
|
|
- createTestTask(taskBo.getId(),taskDto);
|
|
|
+ createTestTask(taskBo.getId(),taskDto, records);
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- private void createTrainTask(Long taskId, CreateTargetIdentificationTaskDto taskDto) {
|
|
|
+ private Map<String, String> createTrainTask(Long taskId, CreateTargetIdentificationTaskDto taskDto) {
|
|
|
List<TaskDto> algTaskList = taskDto.getAlgTaskList();
|
|
|
List<String> trainBatchNumList = taskDto.getTrainBatchNumList();
|
|
|
if (trainBatchNumList.isEmpty()) {
|
|
|
- return;
|
|
|
+ return null;
|
|
|
}
|
|
|
TargetIdentificationSubtaskBo subtask = new TargetIdentificationSubtaskBo();
|
|
|
subtask.setName("训练");
|
|
@@ -222,13 +227,16 @@ public class TargetIdentificationTaskServiceImpl extends BaseServiceImpl<TargetI
|
|
|
subtask.setId(savedTask.getId());
|
|
|
System.out.println("subtask is: " + subtask);
|
|
|
|
|
|
+ Map<String, String> records = new HashMap<>();
|
|
|
+
|
|
|
for (TaskDto algTask : algTaskList) {
|
|
|
// 通过算法id 获取算法配置
|
|
|
Long algorithmId = algTask.getAlgorithmId();
|
|
|
AlgorithmTaskConfigurationVo algorithmModelVo = algorithmTaskConfigurationService.selectById(algorithmId);
|
|
|
|
|
|
- String algUrl = algorithmModelVo.getTestUrl();
|
|
|
+ String algUrl = algorithmModelVo.getTrainUrl();
|
|
|
String algName = algorithmModelVo.getName();
|
|
|
+
|
|
|
List<String> params = List.of(algTask.getParams().split(";;;"));
|
|
|
|
|
|
for (int i = 0; i < trainBatchNumList.size(); i++) {
|
|
@@ -236,14 +244,14 @@ public class TargetIdentificationTaskServiceImpl extends BaseServiceImpl<TargetI
|
|
|
TargetIdentificationSubtaskDetailsBo subtaskDetail = new TargetIdentificationSubtaskDetailsBo();
|
|
|
// 通过算法id获取算法配置
|
|
|
subtaskDetail.setSubtaskId(subtask.getId());
|
|
|
- subtaskDetail.setName(algName);
|
|
|
+ subtaskDetail.setName(algName + "_训练");
|
|
|
subtaskDetail.setStatus(BizConstant.TASK_STATUS_PENDING);
|
|
|
subtaskDetail.setAlgorithmId(algTask.getAlgorithmId());
|
|
|
subtaskDetail.setType(algUrl);
|
|
|
subtaskDetail.setDataBatchNums(batchNum);
|
|
|
subtaskDetail.setParameters(params.get(0));
|
|
|
- // todo 获取预处理路径
|
|
|
String subtaskPath = "/" + UUID.randomUUID().toString().replace("-", "_");
|
|
|
+ records.put(algName, subtaskPath);
|
|
|
subtaskDetail.setPreprocessPath(subtaskPath);
|
|
|
subtaskDetail.setResultPath(subtaskPath + "/result");
|
|
|
subtaskDetail.setIndex((long) i);
|
|
@@ -252,6 +260,7 @@ public class TargetIdentificationTaskServiceImpl extends BaseServiceImpl<TargetI
|
|
|
subtaskDetailsService.insert(subtaskDetail);
|
|
|
}
|
|
|
}
|
|
|
+ return records;
|
|
|
}
|
|
|
|
|
|
public static final String PATH_PREFIX = "ObjectDetection_Web/task";
|
|
@@ -318,7 +327,102 @@ public class TargetIdentificationTaskServiceImpl extends BaseServiceImpl<TargetI
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void createTestTask(Long taskId, CreateTargetIdentificationTaskDto taskDto) {
|
|
|
+ /**
|
|
|
+ * 移动文件到对应文件夹
|
|
|
+ * @param batch
|
|
|
+ * @param path
|
|
|
+ */
|
|
|
+ private void copyFilesToPath(String batch, String path, boolean moveLabelFile) {
|
|
|
+ String[] batches = batch.split(",");
|
|
|
+
|
|
|
+ File dir = new File(PATH_PREFIX + path);
|
|
|
+ if (!dir.exists()) {
|
|
|
+ dir.mkdirs();
|
|
|
+ }
|
|
|
+ dir = new File(PATH_PREFIX + path + "/images");
|
|
|
+ if (!dir.exists()) {
|
|
|
+ dir.mkdirs();
|
|
|
+ }
|
|
|
+ dir = new File(PATH_PREFIX + path + "/labels");
|
|
|
+ if (!dir.exists()) {
|
|
|
+ dir.mkdirs();
|
|
|
+ }
|
|
|
+ dir = new File(PATH_PREFIX + path + "/result");
|
|
|
+ if (!dir.exists()) {
|
|
|
+ dir.mkdirs();
|
|
|
+ }
|
|
|
+
|
|
|
+ for (String batchNum : batches) {
|
|
|
+ List<DataVo> dataVoList = dataService.getDataByBatchNum(batchNum);
|
|
|
+ for (DataVo dataVo : dataVoList) {
|
|
|
+ String[] strings = null;
|
|
|
+ String relativePath = null;
|
|
|
+ File file = null;
|
|
|
+
|
|
|
+ if (dataVo.getLabelurl() != null) {
|
|
|
+ strings = dataVo.getLabelurl().split("/profile");
|
|
|
+ relativePath = "ObjectDetection_Web" + strings[strings.length - 1];
|
|
|
+ file = new File(relativePath);
|
|
|
+ if (file.exists()) {
|
|
|
+ if (!moveLabelFile) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ File dist = new File(PATH_PREFIX + path + "/labels/" + file.getName());
|
|
|
+ FileUtils.copyFile(file, dist);
|
|
|
+ System.out.println("file dist: " + dist.getAbsolutePath());
|
|
|
+ } catch (IOException e) {
|
|
|
+ Log.debug("bug found");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (moveLabelFile) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ strings = dataVo.getUrl().split("/profile");
|
|
|
+ relativePath = "ObjectDetection_Web" + strings[strings.length - 1];
|
|
|
+ file = new File(relativePath);
|
|
|
+ if (file.exists()) {
|
|
|
+ try {
|
|
|
+ File dist = new File(PATH_PREFIX + path + "/images/" + file.getName());
|
|
|
+ FileUtils.copyFile(file, dist);
|
|
|
+ System.out.println("file dist: " + dist.getAbsolutePath());
|
|
|
+ } catch (IOException e) {
|
|
|
+ Log.debug("bug found");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 检查是否有验证集
|
|
|
+ * @param batch
|
|
|
+ */
|
|
|
+ private boolean hasValidationSet(String batch) {
|
|
|
+ String[] batches = batch.split(",");
|
|
|
+
|
|
|
+ for (String batchNum : batches) {
|
|
|
+ List<DataVo> dataVoList = dataService.getDataByBatchNum(batchNum);
|
|
|
+ for (DataVo dataVo : dataVoList) {
|
|
|
+ String[] strings = null;
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(dataVo.getLabelurl())) {
|
|
|
+ strings = dataVo.getLabelurl().split("/profile");
|
|
|
+ String relativePath = "ObjectDetection_Web" + strings[strings.length - 1];
|
|
|
+ File file = new File(relativePath);
|
|
|
+ if (file.exists()) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void createTestTask(Long taskId, CreateTargetIdentificationTaskDto taskDto, Map<String, String> records) {
|
|
|
List<TaskDto> algTaskList = taskDto.getAlgTaskList();
|
|
|
List<String> testBatchNumList = taskDto.getTestBatchNumList();
|
|
|
if (testBatchNumList.isEmpty()) {
|
|
@@ -354,13 +458,25 @@ public class TargetIdentificationTaskServiceImpl extends BaseServiceImpl<TargetI
|
|
|
subtaskDetail.setType(algUrl);
|
|
|
subtaskDetail.setDataBatchNums(batchNum);
|
|
|
subtaskDetail.setParameters(params.get(2));
|
|
|
- // todo 获取预处理路径
|
|
|
String subtaskPath = "/" + UUID.randomUUID().toString().replace("-", "_");
|
|
|
subtaskDetail.setPreprocessPath(subtaskPath);
|
|
|
subtaskDetail.setResultPath(subtaskPath + "/result");
|
|
|
subtaskDetail.setIndex((long) i);
|
|
|
- copyFilesToPath(batchNum, subtaskPath);
|
|
|
|
|
|
+ if (hasValidationSet(batchNum)) {
|
|
|
+ subtaskDetail.setName(algName + "_验证");
|
|
|
+ copyFilesToPath(batchNum, subtaskPath, true);
|
|
|
+ subtaskDetail.setType(algorithmModelVo.getVerifyUrl() + ";;;" + records.get(algName));
|
|
|
+ subtaskDetailsService.insert(subtaskDetail);
|
|
|
+ subtaskPath = "/" + UUID.randomUUID().toString().replace("-", "_");
|
|
|
+ subtaskDetail.setPreprocessPath(subtaskPath);
|
|
|
+ subtaskDetail.setResultPath(subtaskPath + "/result");
|
|
|
+ }
|
|
|
+
|
|
|
+ subtaskDetail.setName(algName + "_测试");
|
|
|
+ subtaskDetail.setPreprocessPath(subtaskDetail.getPreprocessPath() + "/images");
|
|
|
+ subtaskDetail.setType(algorithmModelVo.getTestUrl() + ";;;" + records.get(algName));
|
|
|
+ copyFilesToPath(batchNum, subtaskPath, false);
|
|
|
subtaskDetailsService.insert(subtaskDetail);
|
|
|
}
|
|
|
}
|