Files
Robot_Arm/ml/pipeline.sh
T
Hark 2a0a2e55ad ml: 数据生成 + 可微运动学对拍 + MeanFlow/WTA 策略与闭环仿真 + APG/挖错/ONNX 导出与运行手册
- M1 数据生成器:采样/老师/距离下界认证/时间律/统计/一致性门禁;确定性老师(碰撞次数计时 + resetSession)、pos 任务冻结 J6、--consensus 邻域共识过滤、Dr 类。
- 全流程代码与运行手册:数据打包/可微运动学与对拍/MeanFlow+WTA 模型/闭环仿真/APG/挖错循环/ONNX 导出;webapp 策略运行时 ik-policy.js、?policy=1 接入、tests/policy_bench.cjs;ik-solver 增 pairList/clusterExport/criticalPairs/pairGap/leverTable。
2026-10-18 06:40:23 +08:00

52 lines
3.4 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# 一条龙:bash ml/pipeline.sh <阶段> ;阶段按顺序:
# setup 安装 Python/Node 依赖(torch 需先按 CUDA 版本装好)
# kin 导出运动学/碰撞模型 + JS↔PyTorch 对拍(必须 PASS)
# gate1 老师一致性门禁(决定生成时是否加 --consensus 4)
# gen 生成 5 万条老师轨迹(NPROC 进程;CONSENSUS=1 时加共识过滤)
# prep 打包训练样本
# train 预训练(先 2000 步摸吞吐,再正式训练)
# m5 MeanFlow 头门禁:贴立柱集关安全层穿柱率 ≤ 2%(不过 → 用 configs/wta.json 重训)
# apg APG 首轮微调
# mine 挖错循环(3–6 轮,含门禁回滚)
# export 导出 ONNX(fp16)到 webapp/models/
# bench 部署形态评测(Node,策略 + 安全层)
# all 依次执行 kin → bench
set -e
cd "$(dirname "$0")/.."
NPROC=${NPROC:-$(nproc)}
N_TASKS=${N_TASKS:-50000}
CFG=${CFG:-ml/configs/base.json}
stage=${1:-help}
run() { echo "== $*"; "$@"; }
case $stage in
setup) run pip install -r ml/requirements.txt; (cd ml && npm install --no-audit --no-fund) ;;
kin) run node ml/prep/export_kin.cjs; run node ml/eval/dump_parity.cjs 2000; run python -m ml.eval.check_parity ;;
gate1) mkdir -p ml/data; run node ml/gen/consistency.cjs 300 4242 | tee ml/data/consistency.json ;;
gen) per=$(( (N_TASKS + NPROC - 1) / NPROC ))
if [ -z "${CONSENSUS:-}" ] && [ -f ml/data/consistency.json ]; then
CONSENSUS=$(python -c "import json;print(1 if json.load(open('ml/data/consistency.json'))['consistentByGateRule']<0.9 else 0)")
echo "一致性门禁结果 → CONSENSUS=$CONSENSUS"
fi
extra=""; [ "${CONSENSUS:-0}" = "1" ] && extra="--consensus 4"
run bash ml/gen/run_parallel.sh $per $NPROC 1 "$extra" ;;
prep) run bash ml/prep/run_prep.sh $NPROC ;;
train) run python -m ml.train --samples ml/data/samples --out ml/runs/bench --steps 2000 --no-eval --config $CFG
run python -m ml.train --samples ml/data/samples --out ml/runs/base --config $CFG ;;
m5) [ -f ml/runs/nc_gate.jsonl ] || run python -m ml.mining.mine_round --make-gate 1000 --seed 4321 --mix 0,0,1,0 --name nc_gate.jsonl --out ml/runs
run python -m ml.sim.closed_loop --ckpt ml/runs/base/best.pt --tasks ml/runs/nc_gate.jsonl --n 1000 --out ml/runs/m5_gate.json
python - <<'PY'
import json; r = json.load(open('ml/runs/m5_gate.json'))
print('贴立柱集(关安全层)穿柱率 %.2f%%,到达率 %.2f%%' % (100 * r['collision_rate'], 100 * r['success']))
print('M5 门禁:' + ('通过' if r['collision_rate'] <= 0.02 else '不通过 → CFG=ml/configs/wta.json bash ml/pipeline.sh train'))
PY
;;
apg) run python -m ml.apg.apg_finetune --init ml/runs/base/best.pt --samples ml/data/samples --out ml/runs/apg; cp ml/runs/apg/best.pt ml/runs/current.pt ;;
mine) run bash ml/mining/loop.sh ${ROUNDS:-6} ${APG_STEPS:-1000} ${MINE_N:-50000} ;;
export) ck=ml/runs/current.pt; [ -f $ck ] || ck=ml/runs/base/best.pt
run python -m ml.export_onnx --ckpt $ck --out webapp/models/traj_policy.onnx --fp16 ;;
bench) run node tests/policy_bench.cjs webapp/models/traj_policy.onnx nc,route --nc1000 --out ml/runs/policy_bench.json ;;
all) for s in kin gate1 gen prep train m5 apg mine export bench; do bash ml/pipeline.sh $s; done ;;
*) sed -n '2,16p' "$0" ;;
esac