Parse single epoch training curves

This commit is contained in:
2026-06-30 23:42:11 +08:00
parent 3e9e8ba6f5
commit 6b3a3d7c6d
3 changed files with 39 additions and 12 deletions

View File

@@ -183,7 +183,7 @@ def parse_training_curve(path: Path, max_points: int = 300) -> dict | None:
y = _as_float(row.get(name)) y = _as_float(row.get(name))
if y is not None: if y is not None:
points.append({"x": x, "y": y}) points.append({"x": x, "y": y})
if len(points) >= 2: if points:
values = [point["y"] for point in points] values = [point["y"] for point in points]
series.append({"name": name, "points": points, "last": values[-1], "min": min(values), "max": max(values)}) series.append({"name": name, "points": points, "last": values[-1], "min": min(values), "max": max(values)})
if not series: if not series:

View File

@@ -28,6 +28,26 @@ def test_parse_yolo_results_curve(tmp_path: Path):
assert all("lr/" not in name for name in names) assert all("lr/" not in name for name in names)
def test_parse_single_epoch_yolo_results_curve(tmp_path: Path):
csv_path = tmp_path / "results.csv"
csv_path.write_text(
"\n".join(
[
"epoch,time,train/box_loss,train/seg_loss,metrics/mAP50(M),lr/pg0",
"1,1.0,1.5,3.0,0.12,0.001",
]
),
encoding="utf-8",
)
curve = parse_training_curve(csv_path)
assert curve is not None
assert curve["row_count"] == 1
seg_loss = next(item for item in curve["series"] if item["name"] == "train/seg_loss")
assert seg_loss["points"] == [{"x": 1.0, "y": 3.0}]
def test_results_api_honors_limit(monkeypatch): def test_results_api_honors_limit(monkeypatch):
calls = {} calls = {}

View File

@@ -1764,17 +1764,24 @@ function MiniCurvePlot({ series }: { series: CurveSeries[] }) {
{[0.25, 0.5, 0.75].map((tick) => ( {[0.25, 0.5, 0.75].map((tick) => (
<path key={tick} d={`M ${pad} ${pad + tick * (height - pad * 2)} H ${width - pad}`} className="gridLine" /> <path key={tick} d={`M ${pad} ${pad + tick * (height - pad * 2)} H ${width - pad}`} className="gridLine" />
))} ))}
{series.map((item, index) => ( {series.map((item, index) => {
const color = curveColor(index);
const scaled = item.points.map((point) => ({ x: scaleX(point.x), y: scaleY(point.y) }));
if (scaled.length === 1) {
return <circle key={item.name} cx={scaled[0].x} cy={scaled[0].y} r="4" fill={color} />;
}
return (
<polyline <polyline
key={item.name} key={item.name}
points={item.points.map((point) => `${scaleX(point.x).toFixed(2)},${scaleY(point.y).toFixed(2)}`).join(" ")} points={scaled.map((point) => `${point.x.toFixed(2)},${point.y.toFixed(2)}`).join(" ")}
fill="none" fill="none"
stroke={curveColor(index)} stroke={color}
strokeWidth="2.4" strokeWidth="2.4"
strokeLinejoin="round" strokeLinejoin="round"
strokeLinecap="round" strokeLinecap="round"
/> />
))} );
})}
</svg> </svg>
); );
} }