SparseDrive
目录
简介
模型介绍
SparseDrive是一种基于稀疏化表征的端到端自动驾驶模型,基于Sparse4D的整体思路,模型通过稀疏化进行检测与构图,大大提高了模型的训推速度,并通过并行的轨迹预测与规划模块,将自车的运动状态纳入到场景理解中,提高了模型轨迹预测与规划能力。
支持任务列表
本仓已经支持以下模型任务类型
| 模型 | 任务列表 | 是否支持 |
|---|---|---|
| SparseDrive | 训练 | ✔ |
代码实现
-
参考实现:
url=https://github.com/swc-17/SparseDrive commit_id=52c4c05b6d446b710c8a12eb9fb19d698b33cb2b -
适配昇腾 AI 处理器的实现:
url=https://gitcode.com/Ascend/DrivingSDK.git code_path=model_examples/SparseDrive
准备训练环境
安装昇腾环境
请参考昇腾社区中《Pytorch框架训练环境准备》文档搭建昇腾环境。本仓已支持表1中软件版本。
表 1 昇腾软件版本支持表
| 软件类型 | 首次支持版本 |
|---|---|
| FrameworkPTAdapter | 7.0.0 |
| CANN | 8.1.RC1 |
安装模型环境
当前模型支持的 PyTorch 版本和已知三方库依赖如下表所示。
表 2 版本支持表
| 三方库 | 支持版本 |
|---|---|
| PyTorch | 2.1.0, 2.7.1 |
| mmcv | 1.x |
| mmdet | 2.28.2 |
-
安装Driving SDK
请参考昇腾Driving SDK代码仓说明编译安装Driving SDK。
-
建议使用依赖安装一键配置脚本,可使用如下指令完成后续基础依赖、
mmcv、模型代码patch的安装和更新:bash install_SparseDrive.sh -
源码安装mmcv
git clone -b 1.x https://github.com/open-mmlab/mmcv.git cd mmcv MMCV_WITH_OPS=1 FORCE_NPU=1 python setup.py install -
模型代码Patch
git clone https://github.com/swc-17/SparseDrive.git cp -rf ./test/ SparseDrive cp -rf ./tools/ SparseDrive cp -rf SparseDrive.patch SparseDrive cd SparseDrive git checkout 52c4c05b6d446b710c8a12eb9fb19d698b33cb2b git apply --reject --whitespace=fix SparseDrive.patch -
安装基础依赖
在本目录下执行命令,安装模型需要的依赖。
# torch 2.1.0 依赖安装 pip install -r requirements_torch2.1.0.txt # torch 2.7.1 依赖安装 pip install -r requirements_torch2.7.1.txt
准备数据集
预训练数据集
用户自行获取nuscenes数据集,在源码目录创建软连接data/nuscenes指向解压后的nuscenes数据目录
sparsedrive_path="path/to/sparsedrive"
cd ${sparsedrive_path}
mkdir data
ln -s path/to/nuscenes ./data/nuscenes
运行数据预处理脚本生成SparseDrive模型训练需要的pkl文件与初始锚框
sh test/preprocess.sh
获取预训练权重
下载backbone预训练权重
mkdir ckpt
wget https://download.pytorch.org/models/resnet50-19c8e357.pth -O ckpt/resnet50-19c8e357.pth
快速开始
训练模型
-
单机训练
训练脚本支持命令行参数(支持默认值/关键字参数/位置参数)
--batch_node_size_stage1: stage1的global_batch_size,默认值为64(单卡batch_size=global_batch_size/NPU卡数)--batch_node_size_stage2: stage2的global_batch_size,默认值为48--num_npu: NPU卡数,默认值为8
-
单机多卡精度训练脚本
#stage1默认训练100个epoch,stage2训练10个epoch
bash test/train_8p_full.sh
(option) bash test/train_8p_full.sh 64 48 8
(option) bash test/train_8p_full.sh --batch_node_size_stage1=64 --batch_node_size_stage2=48 --num_npu=8
- 单机多卡性能测试脚本
#stage1和stage2默认训练1000个step
bash test/train_8p_performance.sh
(option) bash test/train_8p_performance.sh 64 48 8
(option) bash test/train_8p_performance.sh --batch_node_size_stage1=64 --batch_node_size_stage2=48 --num_npu=8
# (option)若没有进行全量精度训练,可使用如下命令下载stage1的权重以测试stage2的性能
wget https://github.com/swc-17/SparseDrive/releases/download/v1.0/sparsedrive_stage1.pth -O ckpt/sparsedrive_stage1.pth
训练结果
表 3 训练结果展示表
| 阶段 | 芯片 | 卡数 | global batch size | Precision | FPS | 平均step耗时(s) | amota | L2 |
|---|---|---|---|---|---|---|---|---|
| stage1 | 竞品A | 8p | 64 | fp16 | 41.0 | 1.561 | 0.3764 | - |
| stage1 | Atlas 800T A2 | 8p | 64 | fp16 | 46.3 | 1.382 | 0.3864 | - |
| stage1 | Atlas 800T A3 | 16p | 128 | fp16 | 108.6 | 1.179 | - | - |
| stage1 | Atlas 950 SuperPoD | 8p | 64 | fp16 | 101.3 | 0.632 | 0.3846 | - |
| stage2 | 竞品A | 8p | 48 | fp16 | 35.2 | 1.363 | - | 0.6280 |
| stage2 | Atlas 800T A2 | 8p | 48 | fp16 | 37.9 | 1.265 | - | 0.6069 |
| stage2 | Atlas 800T A3 | 16p | 96 | fp16 | 88.4 | 1.086 | - | - |
| stage2 | Atlas 950 SuperPoD | 8p | 48 | fp16 | 81.8 | 0.587 | - | 0.6169 |
版本说明
变更
2025.04.27:首次发布。
2025.07.07:瓶颈算子优化,刷新性能数据
2025.08.25:训练脚本优化
2026.06.04:新增 A5 模型适配与 Pytorch 2.7.1 支持
FAQ
暂无。