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, * 기존 방식: 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
@@ -350,8 +359,8 @@ public class ModelTestMetricsJobService {
log.info("Best PTH 파일 검색 완료: 총 {}개 발견", bestFiles.size()); log.info("Best PTH 파일 검색 완료: 총 {}개 발견", bestFiles.size());
if (bestFiles.isEmpty()) { if (bestFiles.isEmpty()) {
log.warn(" Best PTH 파일이 하나도 발견되지 않았습니다. 파일명 패턴을 확인하세요."); log.warn("Best PTH 파일이 하나도 발견되지 않았습니다. 파일명 패턴을 확인하세요.");
log.warn(" 예상 패턴: best_changed_{{metricType}}_epoch_{{N}}.pth"); log.warn("예상 패턴: best_changed_{{metricType}}_epoch_{{N}}.pth");
// 디버깅: response 폴더의 모든 .pth 파일 출력 // 디버깅: response 폴더의 모든 .pth 파일 출력
try (Stream<Path> debugStream = Files.list(responsePath)) { try (Stream<Path> debugStream = Files.list(responsePath)) {
@@ -363,10 +372,10 @@ public class ModelTestMetricsJobService {
.collect(Collectors.toList()); .collect(Collectors.toList());
if (!allPthFiles.isEmpty()) { if (!allPthFiles.isEmpty()) {
log.info(" Response 폴더의 .pth 파일 목록:"); log.info("Response 폴더의 .pth 파일 목록:");
allPthFiles.forEach(name -> log.info(" - {}", name)); allPthFiles.forEach(name -> log.info(" - {}", name));
} else { } else {
log.warn(" Response 폴더에 .pth 파일이 전혀 없습니다."); log.warn("Response 폴더에 .pth 파일이 전혀 없습니다.");
} }
} catch (IOException e) { } catch (IOException e) {
log.error("디버깅 중 에러 발생", e); log.error("디버깅 중 에러 발생", e);
@@ -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);