json 생성 수정
This commit is contained in:
@@ -220,8 +220,8 @@ public class ModelTestMetricsJobService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 기존 방식: F-Score 기준 통합 ZIP 파일 생성 파일명: {modelNo}.{modelVer}.{uuid}.zip 포함 파일: model_config.py,
|
* 기존 방식: F-Score 기준 통합 ZIP 파일 생성 파일명: {modelVersion}.zip (예: G4_000001.zip) 포함 파일:
|
||||||
* best_changed_fscore_epoch_N.pth, {modelVersion}.json, yolov8_6th-6m.pt
|
* model_config.py, best_changed_fscore_epoch_N.pth, {modelVersion}.json, yolov8_6th-6m.pt
|
||||||
*
|
*
|
||||||
* @param modelInfo 모델 정보
|
* @param modelInfo 모델 정보
|
||||||
* @param responsePath Response 디렉토리 경로
|
* @param responsePath Response 디렉토리 경로
|
||||||
@@ -239,12 +239,22 @@ public class ModelTestMetricsJobService {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. JSON 파일명: {modelVersion}.json (예: G4_000001.json)
|
// 2. JSON 파일 생성: {modelVersion}.json (예: G4_000001.json)
|
||||||
String legacyJsonFileName = jsonDto.getModelVersion() + ".json";
|
try {
|
||||||
Path legacyJsonPath = responsePath.resolve(legacyJsonFileName);
|
writeJsonFile(
|
||||||
writeJsonFile(jsonDto, legacyJsonPath);
|
jsonDto,
|
||||||
|
Paths.get(
|
||||||
|
responseDir
|
||||||
|
+ "/"
|
||||||
|
+ modelInfo.getUuid()
|
||||||
|
+ "/"
|
||||||
|
+ jsonDto.getModelVersion()
|
||||||
|
+ ".json"));
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
log.info("JSON 파일 생성 완료: {}", legacyJsonFileName);
|
log.info("JSON 파일 생성 완료: {}.json", jsonDto.getModelVersion());
|
||||||
|
|
||||||
// 3. Best Epoch 파일명 찾기 (F-Score 기준)
|
// 3. Best Epoch 파일명 찾기 (F-Score 기준)
|
||||||
ModelTestFileName fileInfo =
|
ModelTestFileName fileInfo =
|
||||||
@@ -257,48 +267,47 @@ public class ModelTestMetricsJobService {
|
|||||||
|
|
||||||
log.info("Best Epoch 파일명: {}.pth", fileInfo.getBestEpochFileName());
|
log.info("Best Epoch 파일명: {}.pth", fileInfo.getBestEpochFileName());
|
||||||
|
|
||||||
// 4. ZIP에 포함할 파일 리스트
|
// 4. ZIP 파일 경로: {modelVersion}.zip (예: G4_000001.zip)
|
||||||
|
Path zipPath =
|
||||||
|
Paths.get(
|
||||||
|
responseDir + "/" + modelInfo.getUuid() + "/" + fileInfo.getModelVersion() + ".zip");
|
||||||
|
|
||||||
|
// 5. ZIP에 포함할 파일 리스트
|
||||||
Set<String> targetNames =
|
Set<String> targetNames =
|
||||||
Set.of(
|
Set.of(
|
||||||
"model_config.py",
|
"model_config.py",
|
||||||
fileInfo.getBestEpochFileName() + ".pth", // best_changed_fscore_epoch_N.pth
|
fileInfo.getBestEpochFileName() + ".pth", // best_changed_fscore_epoch_N.pth
|
||||||
legacyJsonFileName); // {modelVersion}.json
|
fileInfo.getModelVersion() + ".json"); // {modelVersion}.json
|
||||||
|
|
||||||
List<Path> filesToZip = new ArrayList<>();
|
List<Path> files = new ArrayList<>();
|
||||||
|
|
||||||
// Response 폴더에서 파일 수집
|
// Response 폴더에서 파일 수집
|
||||||
try (Stream<Path> stream = Files.list(responsePath)) {
|
try (Stream<Path> stream = Files.list(responsePath)) {
|
||||||
filesToZip.addAll(
|
files.addAll(
|
||||||
stream
|
stream
|
||||||
.filter(Files::isRegularFile)
|
.filter(Files::isRegularFile)
|
||||||
.filter(p -> targetNames.contains(p.getFileName().toString()))
|
.filter(p -> targetNames.contains(p.getFileName().toString()))
|
||||||
.collect(Collectors.toList()));
|
.collect(Collectors.toList()));
|
||||||
}
|
}
|
||||||
|
|
||||||
log.info("Response 폴더에서 수집한 파일 {}개", filesToZip.size());
|
log.info("Response 폴더에서 수집한 파일 {}개", files.size());
|
||||||
|
|
||||||
// PT 파일 추가 (사전학습 모델)
|
// PT 파일 추가 (사전학습 모델)
|
||||||
Path ptPath = findPretrainedModel();
|
try (Stream<Path> stream = Files.list(Path.of(ptPathDir))) {
|
||||||
if (ptPath != null) {
|
files.addAll(
|
||||||
filesToZip.add(ptPath);
|
stream
|
||||||
log.info("사전학습 모델 추가: {}", ptPath.getFileName());
|
.filter(Files::isRegularFile)
|
||||||
} else {
|
.limit(1) // yolov8_6th-6m.pt 파일 1개만
|
||||||
log.warn("사전학습 모델(.pt) 파일을 찾을 수 없습니다.");
|
.collect(Collectors.toList()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 5. ZIP 파일명 생성: {modelNo}.{modelVer}.{uuid}.zip
|
log.info("최종 ZIP에 포함할 파일 {}개", files.size());
|
||||||
String legacyZipFileName =
|
|
||||||
String.format(
|
|
||||||
"%s.zip", jsonDto.getModelVersion() // G4.G4_000001.uuid
|
|
||||||
);
|
|
||||||
|
|
||||||
Path legacyZipPath = responsePath.resolve(legacyZipFileName);
|
|
||||||
|
|
||||||
// 6. ZIP 압축
|
// 6. ZIP 압축
|
||||||
zipFiles(filesToZip, legacyZipPath);
|
zipFiles(files, zipPath);
|
||||||
|
|
||||||
long zipSize = Files.size(legacyZipPath);
|
long zipSize = Files.size(zipPath);
|
||||||
log.info("기존 방식 ZIP 파일 생성 완료: fileName={}, size={} bytes", legacyZipFileName, zipSize);
|
log.info("기존 방식 ZIP 파일 생성 완료: fileName={}, size={} bytes", zipPath.getFileName(), zipSize);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("기존 방식 ZIP 파일 생성 실패: modelId={}", modelInfo.getModelId(), e);
|
log.error("기존 방식 ZIP 파일 생성 실패: modelId={}", modelInfo.getModelId(), e);
|
||||||
@@ -321,8 +330,8 @@ public class ModelTestMetricsJobService {
|
|||||||
// best_changed_{어떤문자든}_epoch_{숫자}.pth 형식의 모든 파일 검색
|
// best_changed_{어떤문자든}_epoch_{숫자}.pth 형식의 모든 파일 검색
|
||||||
Pattern pattern = Pattern.compile("best_changed_(.+?)_epoch_(\\d+)\\.pth");
|
Pattern pattern = Pattern.compile("best_changed_(.+?)_epoch_(\\d+)\\.pth");
|
||||||
|
|
||||||
log.info("📂 Best PTH 파일 검색 시작: path={}", responsePath);
|
log.info("Best PTH 파일 검색 시작: path={}", responsePath);
|
||||||
log.info("🔍 검색 패턴: best_changed_{{metricType}}_epoch_{{N}}.pth");
|
log.info("검색 패턴: best_changed_{{metricType}}_epoch_{{N}}.pth");
|
||||||
|
|
||||||
try (Stream<Path> stream = Files.list(responsePath)) {
|
try (Stream<Path> stream = Files.list(responsePath)) {
|
||||||
stream
|
stream
|
||||||
@@ -449,7 +458,7 @@ public class ModelTestMetricsJobService {
|
|||||||
String zipFileName =
|
String zipFileName =
|
||||||
String.format(
|
String.format(
|
||||||
"%s.%s.zip",
|
"%s.%s.zip",
|
||||||
metricJson.getModelVersion(), // G1.G1_000001.{uuid}
|
metricJson.getModelVersion(), // G1_000001
|
||||||
bestPth.getMetricType()); // fscore/precision/recall
|
bestPth.getMetricType()); // fscore/precision/recall
|
||||||
|
|
||||||
Path zipPath = responsePath.resolve(zipFileName);
|
Path zipPath = responsePath.resolve(zipFileName);
|
||||||
|
|||||||
Reference in New Issue
Block a user