1
This commit is contained in:
@@ -15,7 +15,6 @@
|
||||
project 训练输出目录(相对 workdir,末尾自动拼 name)
|
||||
log_file 每 epoch 一行 JSON 的进度日志(相对 workdir)
|
||||
result_file 结束结果 JSON(相对 workdir)
|
||||
artifact_zip 产物打包(best.pt + results.csv + 曲线,相对 workdir)
|
||||
|
||||
产物契约:
|
||||
log_file {"epoch":1,"total":150,"metrics":{"metrics/mAP50(B)":0.87,...}}
|
||||
@@ -32,7 +31,6 @@ import os
|
||||
import struct
|
||||
import sys
|
||||
import traceback
|
||||
import zipfile
|
||||
from pathlib import Path
|
||||
|
||||
# 抗尺度漂移(与人工训练基线一致):随机缩放输入 0.5~1.5x
|
||||
@@ -58,7 +56,9 @@ def on_fit_epoch_end(trainer):
|
||||
|
||||
|
||||
def register_callback():
|
||||
from ultralytics.utils.callbacks import callbacks
|
||||
# ultralytics ≥8.4 中 callbacks 字典改由 get_default_callbacks() 取得
|
||||
from ultralytics.utils.callbacks import get_default_callbacks
|
||||
callbacks = get_default_callbacks()
|
||||
callbacks["on_fit_epoch_end"].append(on_fit_epoch_end)
|
||||
|
||||
|
||||
@@ -205,17 +205,6 @@ def check_tflite(path, imgsz):
|
||||
return {"ok": False, "reason": f"解析失败: {e}", "inputs": [], "outputs": []}
|
||||
|
||||
|
||||
def build_artifact_zip(zip_path, save_dir):
|
||||
Path(zip_path).parent.mkdir(parents=True, exist_ok=True)
|
||||
with zipfile.ZipFile(zip_path, "w", zipfile.ZIP_DEFLATED) as zf:
|
||||
for p in (save_dir / "weights" / "best.pt", save_dir / "results.csv"):
|
||||
if p.exists():
|
||||
zf.write(p, arcname=p.name)
|
||||
# 曲线/混淆矩阵等绘图产物在 save_dir 根目录
|
||||
for p in sorted(save_dir.glob("*.png")) + sorted(save_dir.glob("*.jpg")):
|
||||
zf.write(p, arcname=p.name)
|
||||
|
||||
|
||||
def main():
|
||||
ap = argparse.ArgumentParser(description="observer 训练任务脚本(Go --task-json 驱动)")
|
||||
ap.add_argument("--task-json", required=True, help="任务参数 JSON 文件路径")
|
||||
@@ -239,7 +228,6 @@ def main():
|
||||
|
||||
log_file = task_path("log_file")
|
||||
result_file = task_path("result_file")
|
||||
artifact_zip = task_path("artifact_zip")
|
||||
global _LOG
|
||||
_LOG = None
|
||||
try:
|
||||
@@ -273,7 +261,8 @@ def main():
|
||||
|
||||
best_tflite = find_best_tflite(save_dir)
|
||||
if best_tflite is None:
|
||||
model.export(format="tflite", imgsz=imgsz)
|
||||
# ultralytics ≥8.4 中 tflite 为废弃格式(走 onnx2tf 链路),litert 是官方替代,产物同为 best.tflite
|
||||
model.export(format="litert", imgsz=imgsz)
|
||||
best_tflite = find_best_tflite(save_dir)
|
||||
if best_tflite is None:
|
||||
raise RuntimeError("tflite 导出失败:weights 目录下未找到任何 .tflite 产物")
|
||||
@@ -290,8 +279,7 @@ def main():
|
||||
if isinstance(v, (int, float)) and math.isfinite(v):
|
||||
clean_metrics[k] = round(float(v), 5)
|
||||
|
||||
build_artifact_zip(artifact_zip, save_dir)
|
||||
# best_tflite 相对 workdir,Go 侧按此路径拉取
|
||||
# best_tflite 相对 workdir,Go 侧按此路径拉取(不再打包 zip,仅回传 tflite)
|
||||
write_result(result_file, {
|
||||
"metrics": clean_metrics,
|
||||
"names": names,
|
||||
|
||||
Reference in New Issue
Block a user