From 8fa7a9d1420dc3863a21fd4aeca34074901d65da Mon Sep 17 00:00:00 2001 From: Shaun Zhou Date: Mon, 21 Sep 2026 11:03:14 +0800 Subject: [PATCH] =?UTF-8?q?fix(ml-backend):=20=E9=87=8D=E8=AE=AD=E5=90=8E?= =?UTF-8?q?=E7=9C=9F=E6=AD=A3=E5=88=87=E5=88=B0=E6=96=B0=E6=9D=83=E9=87=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 重训脚本是 ML backend 的子进程,继承了后端 export 的 YOLO_WEIGHTS。启动脚本里 ${YOLO_WEIGHTS:-默认值} 于是让旧值赢了——实测重训完成后后端仍加载旧权重, current.pt 软链接形同虚设。同样被继承的还有 RETRAIN_EXTRA_SET,会让下次训练 沿用上次的冒烟参数(epochs=1)。 重启时显式传 YOLO_WEIGHTS 并 env -u 清掉 RETRAIN_EXTRA_SET。 Co-Authored-By: Claude Opus 5 --- scripts/retrain_from_label_studio.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/retrain_from_label_studio.sh b/scripts/retrain_from_label_studio.sh index 6f8eec8..2e3edbb 100755 --- a/scripts/retrain_from_label_studio.sh +++ b/scripts/retrain_from_label_studio.sh @@ -44,7 +44,11 @@ echo "--- 3/4 训练 -> $WORK_DIR" echo "--- 4/4 切换权重并重启 ML backend" # 指向最新权重的稳定软链接:启动脚本读它,于是换模型不用改任何脚本 ln -sfn "$WORK_DIR/weights/best.pt" "$REPO/runs/detect/current.pt" -bash "$REPO/scripts/start_ml_backend.sh" +# 必须显式传 YOLO_WEIGHTS 并清掉继承来的变量:本脚本是旧后端的子进程, +# 它环境里已经 export 了 YOLO_WEIGHTS(旧权重)和可能的 RETRAIN_EXTRA_SET(冒烟参数), +# 不清掉的话新后端会继续用旧模型、下次训练也会沿用冒烟参数 +env -u RETRAIN_EXTRA_SET YOLO_WEIGHTS="$REPO/runs/detect/current.pt" \ + bash "$REPO/scripts/start_ml_backend.sh" echo "===== [$(date '+%F %T')] 重训完成:$WORK_DIR =====" echo "指标见 $WORK_DIR/metrics.json,曲线见 $WORK_DIR/results.png"