You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
2.9 KiB
2.9 KiB
YOLO 训练结果解析功能说明
功能概述
在 YoloOperationServiceImpl.java 中新增了自动检测和解析 YOLO 训练结果的功能,当训练日志中出现 "Results saved to" 时,系统会:
- 自动提取保存路径:从日志中解析出类似
D:\data\train\1231_5\runs\train\train18的路径 - 解析识别率信息:从保存路径中的
results.csv文件或其他日志文件中提取精度、召回率、mAP 等指标 - 保存到数据库:将路径和识别率信息保存到
TrainResultDO表中
新增方法
1. detectAndParseResultsSaved(String logLine, YoloConfig config, Integer trainId)
- 检测日志中是否包含 "Results saved to" 或 "Saved to" 关键字
- 调用后续方法进行路径提取和识别率解析
2. extractSavedPath(String logLine)
- 使用正则表达式从日志行中提取保存路径
- 支持多种格式,如带引号、带统计信息等
3. parseAccuracyFromSavedPath(String savedPath, YoloConfig config, Integer trainId)
- 查找保存目录中的
results.csv文件 - 解析 CSV 文件中的最后一行(最新结果)
- 提取 precision、recall、mAP50、mAP50-95 等指标
4. parseResultsCsv(File csvFile, YoloConfig config, Integer trainId)
- 解析 YOLO 生成的
results.csv文件 - CSV 格式通常为:
epoch, train/box_loss, train/cls_loss, train/dfl_loss, metrics/precision, metrics/recall, metrics/mAP50, metrics/mAP50-95
5. saveAccuracyToDatabase(Integer trainId, double precision, double recall, double map)
- 将解析到的识别率保存到数据库
- 格式:
precision:0.8521,recall:0.7432,map:0.8123
集成位置
在 trainAsync 方法中,已经集成到日志读取循环中:
if (stdoutLine != null) {
// ... 现有代码 ...
// 检测 "Results saved to" 并解析路径和识别率
detectAndParseResultsSaved(stdoutLine, config, trainId);
}
if (stderrLine != null) {
// ... 现有代码 ...
// 检测 "Results saved to" 并解析路径和识别率
detectAndParseResultsSaved(stderrLine, config, trainId);
}
预期输出格式
当 YOLO 训练完成时,日志中会出现类似内容:
Results saved to D:\data\train\1231_5\runs\train\train18
系统会自动:
- 提取路径:
D:\data\train\1231_5\runs\train\train18 - 查找并解析该目录下的
results.csv文件 - 保存路径和识别率到数据库
注意事项
- 文件权限:确保 Java 进程有权限访问 YOLO 保存的文件
- CSV 格式:依赖 YOLO 标准的
results.csv输出格式 - 异步处理:识别率解析不会阻塞训练过程
- 错误处理:解析失败不会影响训练完成状态
数据库字段
保存的识别率格式:
-- TrainResultDO 表的 rate 字段
precision:0.8521,recall:0.7432,map:0.8123
路径字段:
-- TrainResultDO 表的 path 字段
D:\data\train\1231_5\runs\train\train18