json 생성 수정

This commit is contained in:
2026-04-09 15:05:16 +09:00
parent 7db77226b7
commit e64b1f15ba

View File

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