141 lines
4.6 KiB
Plaintext
141 lines
4.6 KiB
Plaintext
|
|
========================================================================
|
|||
|
|
BEVFusion 剪枝工具准备完成总结
|
|||
|
|
========================================================================
|
|||
|
|
更新时间: 2025-10-30
|
|||
|
|
|
|||
|
|
✅ 所有工具已准备就绪!
|
|||
|
|
|
|||
|
|
========================================================================
|
|||
|
|
核心问题回答: 剪枝需要重新训练吗?
|
|||
|
|
========================================================================
|
|||
|
|
|
|||
|
|
答案: ❌ 不需要完全重新训练,✅ 只需要短期微调
|
|||
|
|
|
|||
|
|
对比:
|
|||
|
|
完全重新训练: 20-24 epochs, 7-8天
|
|||
|
|
剪枝后微调: 3-5 epochs, 12-15小时 ← 快30倍!
|
|||
|
|
|
|||
|
|
原因:
|
|||
|
|
- 剪枝保留了epoch_23学到的特征
|
|||
|
|
- 只需要调整剩余通道的权重
|
|||
|
|
- 使用很小的学习率微调
|
|||
|
|
- 起点好,收敛快
|
|||
|
|
|
|||
|
|
========================================================================
|
|||
|
|
已创建的工具
|
|||
|
|
========================================================================
|
|||
|
|
|
|||
|
|
📚 文档(5个):
|
|||
|
|
1. 模型分析结果与优化方案.md - 分析结果和方案
|
|||
|
|
2. 模型优化启动计划.md - 完整优化计划
|
|||
|
|
3. 模型优化_快速开始.md - 快速指南
|
|||
|
|
4. 剪枝工具使用指南.md - 详细使用说明 ⭐
|
|||
|
|
5. EPOCH23_训练中的评估结果.md - Baseline数据
|
|||
|
|
|
|||
|
|
🛠️ 工具脚本(4个):
|
|||
|
|
1. tools/pruning/prune_bevfusion_builtin.py - 剪枝主脚本 ⭐
|
|||
|
|
2. tools/analysis/analyze_checkpoint.py - 模型分析
|
|||
|
|
3. 一键剪枝和微调.sh - 自动化脚本
|
|||
|
|
4. 准备剪枝工具.sh - 工具准备
|
|||
|
|
|
|||
|
|
📊 分析结果:
|
|||
|
|
- Epoch 23: 45.72M参数, 174MB (FP32)
|
|||
|
|
- Camera Backbone: 27.55M (60%) ← 最大模块
|
|||
|
|
- 目标: 剪枝到32M (-30%)
|
|||
|
|
|
|||
|
|
========================================================================
|
|||
|
|
立即可执行的命令
|
|||
|
|
========================================================================
|
|||
|
|
|
|||
|
|
快速测试(5分钟):
|
|||
|
|
python tools/pruning/prune_bevfusion_builtin.py \
|
|||
|
|
--checkpoint runs/enhanced_from_epoch19/epoch_23.pth \
|
|||
|
|
--output pruning_results/test_pruned.pth \
|
|||
|
|
--target-ratio 0.80
|
|||
|
|
|
|||
|
|
正式剪枝(15分钟):
|
|||
|
|
python tools/pruning/prune_bevfusion_builtin.py \
|
|||
|
|
--checkpoint runs/enhanced_from_epoch19/epoch_23.pth \
|
|||
|
|
--output pruning_results/bevfusion_pruned_32M.pth \
|
|||
|
|
--target-ratio 0.70
|
|||
|
|
|
|||
|
|
一键完整流程:
|
|||
|
|
bash 一键剪枝和微调.sh
|
|||
|
|
|
|||
|
|
========================================================================
|
|||
|
|
微调训练(剪枝后执行,12小时)
|
|||
|
|
========================================================================
|
|||
|
|
|
|||
|
|
启动命令:
|
|||
|
|
torchpack dist-run -np 8 python tools/train.py \
|
|||
|
|
configs/.../multitask_enhanced_phase1_HIGHRES.yaml \
|
|||
|
|
--load_from pruning_results/bevfusion_pruned_32M.pth \
|
|||
|
|
--run-dir runs/pruned_finetune \
|
|||
|
|
--cfg-options \
|
|||
|
|
max_epochs=3 \
|
|||
|
|
optimizer.lr=5.0e-6 \
|
|||
|
|
data.workers_per_gpu=0
|
|||
|
|
|
|||
|
|
建议执行时间:
|
|||
|
|
- 等Stage 1完成后(~9天后)
|
|||
|
|
- 或者现在使用GPU 4-7(不影响Stage 1)
|
|||
|
|
|
|||
|
|
========================================================================
|
|||
|
|
预期结果
|
|||
|
|
========================================================================
|
|||
|
|
|
|||
|
|
剪枝后(立即):
|
|||
|
|
参数量: 45.72M → 32M (-30%)
|
|||
|
|
大小: 174MB → 122MB
|
|||
|
|
精度: 预计下降3-5%(未微调)
|
|||
|
|
|
|||
|
|
微调后(12小时):
|
|||
|
|
参数量: 32M
|
|||
|
|
大小: 122MB (FP32) → 30MB (INT8后)
|
|||
|
|
精度损失: <2%
|
|||
|
|
NDS: ~0.680-0.690
|
|||
|
|
mAP: ~0.630-0.640
|
|||
|
|
|
|||
|
|
========================================================================
|
|||
|
|
下一步建议
|
|||
|
|
========================================================================
|
|||
|
|
|
|||
|
|
选项A: 现在测试剪枝(5分钟,推荐)
|
|||
|
|
→ 快速验证工具可用
|
|||
|
|
→ 查看剪枝效果
|
|||
|
|
→ 不影响任何训练
|
|||
|
|
|
|||
|
|
选项B: 现在正式剪枝(15分钟)
|
|||
|
|
→ 生成剪枝模型
|
|||
|
|
→ 等Stage 1完成后微调
|
|||
|
|
→ 提前准备好
|
|||
|
|
|
|||
|
|
选项C: 等待Stage 1完成再剪枝
|
|||
|
|
→ 更稳妥
|
|||
|
|
→ 集中处理
|
|||
|
|
→ 避免资源冲突
|
|||
|
|
|
|||
|
|
========================================================================
|
|||
|
|
推荐: 选项A(现在测试)
|
|||
|
|
========================================================================
|
|||
|
|
|
|||
|
|
原因:
|
|||
|
|
✓ 只需5分钟
|
|||
|
|
✓ 验证工具正常
|
|||
|
|
✓ 了解剪枝效果
|
|||
|
|
✓ 完全不影响Stage 1训练
|
|||
|
|
✓ 提前发现问题
|
|||
|
|
|
|||
|
|
执行:
|
|||
|
|
cd /workspace/bevfusion
|
|||
|
|
|
|||
|
|
python tools/pruning/prune_bevfusion_builtin.py \
|
|||
|
|
--checkpoint runs/enhanced_from_epoch19/epoch_23.pth \
|
|||
|
|
--output pruning_results/test_pruned_20percent.pth \
|
|||
|
|
--target-ratio 0.80
|
|||
|
|
|
|||
|
|
python tools/analysis/analyze_checkpoint.py \
|
|||
|
|
pruning_results/test_pruned_20percent.pth
|
|||
|
|
|
|||
|
|
========================================================================
|