|
@@ -228,12 +228,20 @@ public class TargetIdentificationTaskServiceImpl extends BaseServiceImpl<TargetI
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 创建验证任务
|
|
|
+ * 如果有验证集(testBatchNumList)则在任务目录下创建train文件夹下放trainBatchNumList的数据
|
|
|
+ * 创建val文件夹下放testBatchNumList有标注的数据
|
|
|
+ * 如果没有验证集(testBatchNumList)则在任务目录下直接创建image、label、result等文件夹
|
|
|
+ * @param taskId
|
|
|
+ * @param taskDto
|
|
|
+ * @return
|
|
|
+ */
|
|
|
private Map<String, String> createTrainTask(Long taskId, CreateTargetIdentificationTaskDto taskDto) {
|
|
|
List<TaskDto> algTaskList = taskDto.getAlgTaskList();
|
|
|
List<String> trainBatchNumList = taskDto.getTrainBatchNumList();
|
|
|
- if (trainBatchNumList.isEmpty()) {
|
|
|
- return null;
|
|
|
- }
|
|
|
+ List<String> testBatchNumList = taskDto.getTestBatchNumList();
|
|
|
+ boolean hasValidate = false;
|
|
|
TargetIdentificationSubtaskBo subtask = new TargetIdentificationSubtaskBo();
|
|
|
subtask.setName("训练");
|
|
|
subtask.setStatus(BizConstant.TASK_STATUS_PENDING);
|
|
@@ -256,6 +264,17 @@ public class TargetIdentificationTaskServiceImpl extends BaseServiceImpl<TargetI
|
|
|
|
|
|
List<String> params = List.of(algTask.getParams().split(";;;"));
|
|
|
|
|
|
+ if (testBatchNumList != null && !testBatchNumList.isEmpty()) {
|
|
|
+ // 检查是否有验证集
|
|
|
+ for (String batchNum : testBatchNumList) {
|
|
|
+ boolean hasValidationSet = hasValidationSet(batchNum);
|
|
|
+ if(hasValidationSet){
|
|
|
+ hasValidate = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }}
|
|
|
+
|
|
|
+
|
|
|
for (int i = 0; i < trainBatchNumList.size(); i++) {
|
|
|
String batchNum = trainBatchNumList.get(i);
|
|
|
TargetIdentificationSubtaskDetailsBo subtaskDetail = new TargetIdentificationSubtaskDetailsBo();
|
|
@@ -272,7 +291,19 @@ public class TargetIdentificationTaskServiceImpl extends BaseServiceImpl<TargetI
|
|
|
subtaskDetail.setPreprocessPath(subtaskPath);
|
|
|
subtaskDetail.setResultPath(subtaskPath + "/result");
|
|
|
subtaskDetail.setIndex((long) i);
|
|
|
- copyFilesToPath(batchNum, subtaskPath);
|
|
|
+
|
|
|
+ // 如果有验证集(testBatchNumList)则在任务目录下创建train文件夹下放trainBatchNumList的数据
|
|
|
+ // 创建val文件夹下放testBatchNumList有标注的数据
|
|
|
+ // 如果没有验证集(testBatchNumList)则在任务目录下直接创建image、label、result等文件夹
|
|
|
+ if(hasValidate){
|
|
|
+ String testBatchNum = testBatchNumList.get(0);
|
|
|
+ // 创建
|
|
|
+ copyFilesToPath(batchNum, subtaskPath, "/train");
|
|
|
+ copyFilesToPath(testBatchNum, subtaskPath,"/val", true);
|
|
|
+ } else {
|
|
|
+ copyFilesToPath(batchNum, subtaskPath,"");
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
subtaskDetailsService.insert(subtaskDetail);
|
|
|
}
|
|
@@ -289,18 +320,19 @@ public class TargetIdentificationTaskServiceImpl extends BaseServiceImpl<TargetI
|
|
|
* @param batch
|
|
|
* @param path
|
|
|
*/
|
|
|
- private void copyFilesToPath(String batch, String path) {
|
|
|
+ private void copyFilesToPath(String batch, String path , String namePrefix) {
|
|
|
+ String all_path = path + namePrefix;
|
|
|
String[] batches = batch.split(",");
|
|
|
|
|
|
- File dir = new File(PATH_PREFIX + path);
|
|
|
+ File dir = new File(PATH_PREFIX + all_path);
|
|
|
if (!dir.exists()) {
|
|
|
dir.mkdirs();
|
|
|
}
|
|
|
- dir = new File(PATH_PREFIX + path + "/images");
|
|
|
+ dir = new File(PATH_PREFIX + all_path + "/images");
|
|
|
if (!dir.exists()) {
|
|
|
dir.mkdirs();
|
|
|
}
|
|
|
- dir = new File(PATH_PREFIX + path + "/labels");
|
|
|
+ dir = new File(PATH_PREFIX + all_path + "/labels");
|
|
|
if (!dir.exists()) {
|
|
|
dir.mkdirs();
|
|
|
}
|
|
@@ -318,12 +350,13 @@ public class TargetIdentificationTaskServiceImpl extends BaseServiceImpl<TargetI
|
|
|
String relativePath = WORK_DIR + strings[strings.length - 1];
|
|
|
relativePath = relativePath.replace("\\", "/").replace("//", "/");
|
|
|
File file = new File(relativePath);
|
|
|
- System.out.println(file.getAbsolutePath());
|
|
|
+ log.info(file.getAbsolutePath());
|
|
|
+ System.out.println();
|
|
|
if (file.exists()) {
|
|
|
try {
|
|
|
- File dist = new File(PATH_PREFIX + path + "/images/" + file.getName());
|
|
|
+ File dist = new File(PATH_PREFIX + all_path + "/images/" + file.getName());
|
|
|
FileUtils.copyFile(file, dist);
|
|
|
- System.out.println("file dist: " + dist.getAbsolutePath());
|
|
|
+ log.info("file dist: " + dist.getAbsolutePath());
|
|
|
} catch (IOException e) {
|
|
|
Log.debug("bug found");
|
|
|
continue;
|
|
@@ -336,9 +369,9 @@ public class TargetIdentificationTaskServiceImpl extends BaseServiceImpl<TargetI
|
|
|
file = new File(relativePath);
|
|
|
if (file.exists()) {
|
|
|
try {
|
|
|
- File dist = new File(PATH_PREFIX + path + "/labels/" + file.getName());
|
|
|
+ File dist = new File(PATH_PREFIX + all_path + "/labels/" + file.getName());
|
|
|
FileUtils.copyFile(file, dist);
|
|
|
- System.out.println("file dist: " + dist.getAbsolutePath());
|
|
|
+ log.info("file dist: " + dist.getAbsolutePath());
|
|
|
} catch (IOException e) {
|
|
|
Log.debug("bug found");
|
|
|
continue;
|
|
@@ -354,18 +387,19 @@ public class TargetIdentificationTaskServiceImpl extends BaseServiceImpl<TargetI
|
|
|
* @param batch
|
|
|
* @param path
|
|
|
*/
|
|
|
- private void copyFilesToPath(String batch, String path, boolean moveLabelFile) {
|
|
|
+ private void copyFilesToPath(String batch, String path, String namePrefix, boolean moveLabelFile) {
|
|
|
+ String allPath = path + namePrefix;
|
|
|
String[] batches = batch.split(",");
|
|
|
|
|
|
- File dir = new File(PATH_PREFIX + path);
|
|
|
+ File dir = new File(PATH_PREFIX + allPath);
|
|
|
if (!dir.exists()) {
|
|
|
dir.mkdirs();
|
|
|
}
|
|
|
- dir = new File(PATH_PREFIX + path + "/images");
|
|
|
+ dir = new File(PATH_PREFIX + allPath + "/images");
|
|
|
if (!dir.exists()) {
|
|
|
dir.mkdirs();
|
|
|
}
|
|
|
- dir = new File(PATH_PREFIX + path + "/labels");
|
|
|
+ dir = new File(PATH_PREFIX + allPath + "/labels");
|
|
|
if (!dir.exists()) {
|
|
|
dir.mkdirs();
|
|
|
}
|
|
@@ -393,9 +427,9 @@ public class TargetIdentificationTaskServiceImpl extends BaseServiceImpl<TargetI
|
|
|
continue;
|
|
|
}
|
|
|
try {
|
|
|
- File dist = new File(PATH_PREFIX + path + "/labels/" + file.getName());
|
|
|
+ File dist = new File(PATH_PREFIX + allPath + "/labels/" + file.getName());
|
|
|
FileUtils.copyFile(file, dist);
|
|
|
- System.out.println("file dist: " + dist.getAbsolutePath());
|
|
|
+ log.info("file dist: " + dist.getAbsolutePath());
|
|
|
} catch (IOException e) {
|
|
|
log.error("e happens: {}", e.getMessage());
|
|
|
continue;
|
|
@@ -412,10 +446,10 @@ public class TargetIdentificationTaskServiceImpl extends BaseServiceImpl<TargetI
|
|
|
file = new File(relativePath);
|
|
|
if (file.exists()) {
|
|
|
try {
|
|
|
- File dist = new File(PATH_PREFIX + path + "/images/" + file.getName());
|
|
|
+ File dist = new File(PATH_PREFIX + allPath + "/images/" + file.getName());
|
|
|
log.info("get filename: {}", file.getName());
|
|
|
FileUtils.copyFile(file, dist);
|
|
|
- System.out.println("file dist: " + dist.getAbsolutePath());
|
|
|
+ log.info("file dist: " + dist.getAbsolutePath());
|
|
|
} catch (IOException e) {
|
|
|
Log.debug("bug found");
|
|
|
continue;
|
|
@@ -514,7 +548,7 @@ public class TargetIdentificationTaskServiceImpl extends BaseServiceImpl<TargetI
|
|
|
if (hasValidationSet(batchNum)) {
|
|
|
subtaskDetail.setName(algName + "_验证");
|
|
|
subtaskDetail.setParameters(params.get(1));
|
|
|
- copyFilesToPath(batchNum, subtaskPath, true);
|
|
|
+ copyFilesToPath(batchNum, subtaskPath, "",true);
|
|
|
subtaskDetail.setType(algorithmModelVo.getVerifyUrl() + ";;;" + (records != null ? records.get(algName) : ""));
|
|
|
subtaskDetailsService.insert(subtaskDetail);
|
|
|
// reset to '测试'
|
|
@@ -528,7 +562,7 @@ public class TargetIdentificationTaskServiceImpl extends BaseServiceImpl<TargetI
|
|
|
subtaskDetail.setPreprocessPath(subtaskDetail.getPreprocessPath() + "/images");
|
|
|
subtaskDetail.setType(algorithmModelVo.getTestUrl() + ";;;" + (records != null ? records.get(algName) : ""));
|
|
|
if (hasTestSet(batchNum)) {
|
|
|
- copyFilesToPath(batchNum, subtaskPath, false);
|
|
|
+ copyFilesToPath(batchNum, subtaskPath, "", false);
|
|
|
subtaskDetailsService.insert(subtaskDetail);
|
|
|
}
|
|
|
}
|