news 2026/5/9 7:45:03

SparseDrive运行记录

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
SparseDrive运行记录

文章目录

  • 一.安装环境
  • 二.运行

一.安装环境

nvcc-V conda create-n sparsedrive python=3.8-y conda activate sparsedrive pip install torch==2.0.0torchvision==0.15.1torchaudio==2.0.1--index-url https://download.pytorch.org/whl/cu118 (必须cuda11.6及以上,我用的cuda11.8)pip install mmcv-full==1.7.2-f https://download.openmmlab.com/mmcv/dist/cu118/torch2.0/index.htmlpip install-r requirement.txt or服务器的是cuda12.X conda create-n sparsedrive python=3.10-y conda activate sparsedrive pip install torch==2.1.0torchvision==0.16.0torchaudio==2.1.0--index-url https://download.pytorch.org/whl/cu121pip install mmcv-full==1.7.2-f https://download.openmmlab.com/mmcv/dist/cu121/torch2.1/index.html --only-binary mmcv-fullpip install-r requirement.txt(个别库版本升级了) (numpy==1.23.5mmcv_full==1.7.2mmdet==2.28.2urllib3==1.26.16pyquaternion==0.9.9nuscenes-devkit==1.1.10yapf==0.33.0tensorboard==2.14.0motmetrics==1.1.3pandas==1.5.3flash-attn==2.3.3opencv-python==4.8.1.78prettytable==3.7.0scikit-learn==1.3.0) 注:flash-attn==2.3.3,建议本地下载安装 wget https://github.com/Dao-AILab/flash-attention/releases/download/v2.3.3/flash_attn-2.3.3+cu122torch2.1cxx11abiFALSE-cp310-cp310-linux_x86_64.whlpip install flash_attn-2.3.3+cu122torch2.1cxx11abiFALSE-cp310-cp310-linux_x86_64.whl--no-build-isolation python-c"import flash_attn; print('安装成功!')"

二.运行

1、编译可变形聚合CUDA算子
代码如下(示例):

cd projects/mmdet3d_plugin/ops export CUDA_HOME=/usr/local/cuda python3 setup.py develop 出现Installed/home/1/SparseDrive-main/projects/mmdet3d_plugin/ops Processing dependenciesfordeformable-aggregation-ext==0.0.0Finished processing dependenciesfordeformable-aggregation-ext==0.0.0则安装成功 cd../../../

2、配置nuscenes数据集
在主目录下创建data文件夹,在data创建nuscenes文件夹,可以从 https://www.nuscenes.org/nuscenes 下载数据集,放置下载的数据(实例只下载了v1.0-mini数据集,注意can_bus和maps需要下载全的,不仅仅只有mini内的数据,),对nuscenes中的v1.0-mini复制一份并改名为v1.0-trainval。
(注释:另感兴趣需要OCC数据对于Occupancy预测任务,还需要下载OCC的GT,可以从 https://github.com/CVPR2023-3D-Occupancy-Prediction/CVPR2023-3D-Occupancy-Prediction 下载数据集。 这里建议将下载好的数据集,解压到nuscense数据集文件夹中的 occ3d/gts 下,本文不涉及OCC。)
maps文件内容

3、创建数据

sh scripts/create_data.sh

在data/infos/文件夹下,生成mini文件夹,文件夹内生成以下两个pkl文件:
4、通过K-means生成锚点
采用的是mini,所以修改/tools/kmeans/的代码路径:

#fp='data/infos/nuscenes_infos_train.pkl'fp='data/infos/mini/nuscenes_infos_train.pkl'

再运行

sh scripts/kmeans.sh

采用mini可正常生成det、map和motion.npy,但kmeans_plan_6.npy报错,对tools/kmeans/kmeans_plan.py代码进行修改,

# 原始的all数据集#clusters=[]#fortrajs in navi_trajs:#trajs=np.concatenate(trajs,axis=0).reshape(-1,12)#cluster=KMeans(n_clusters=K).fit(trajs).cluster_centers_#cluster=cluster.reshape(-1,6,2)#clusters.append(cluster)#forj inrange(K):#plt.scatter(cluster[j,:,0],cluster[j,:,1])#plt.savefig(f'vis/kmeans/plan_{K}',bbox_inches='tight')#plt.close()#clusters=np.stack(clusters,axis=0)#np.save(f'data/kmeans/kmeans_plan_{K}.npy',clusters)# 修改代码适配mini数据集 clusters=[]clusters.append(np.zeros((6,6,2)))fortrajs in navi_trajs[1:]:#fortrajs in navi_trajs:trajs=np.concatenate(trajs,axis=0).reshape(-1,12)cluster=KMeans(n_clusters=K).fit(trajs).cluster_centers_ cluster=cluster.reshape(-1,6,2)clusters.append(cluster)forj inrange(K):plt.scatter(cluster[j,:,0],cluster[j,:,1])plt.savefig(f'vis/kmeans/plan_{K}',bbox_inches='tight')plt.close()clusters=np.stack(clusters,axis=0)np.save(f'data/kmeans/kmeans_plan_{K}.npy',clusters)

5、下载预训练权重

mkdir ckpt wget https://download.pytorch.org/models/resnet50-19c8e357.pth -O ckpt/resnet50-19c8e357.pth

6、训练和测试(硬件版本太低无法训练)

#trainsh scripts/train.sh 报错如下 warnings.warn(usage:train.py[-h][--work-dir WORK_DIR][--resume-from RESUME_FROM][--no-validate][--gpus GPUS|--gpu-ids GPU_IDS[GPU_IDS...]][--seed SEED][--deterministic][--options OPTIONS[OPTIONS...]][--cfg-options CFG_OPTIONS[CFG_OPTIONS...]][--dist-url DIST_URL][--gpus-per-machine GPUS_PER_MACHINE][--launcher{none,pytorch,slurm,mpi,mpi_nccl}][--local_rank LOCAL_RANK][--autoscale-lr]config train.py:error:unrecognized arguments:--local-rank=0ERROR:torch.distributed.elastic.multiprocessing.api:failed(exitcode:2)local_rank:0(pid:15735)of binary:/home/1/anaconda3/envs/sparsedrive/bin/python3Traceback(most recent call last):File"/home/1/anaconda3/envs/sparsedrive/lib/python3.8/runpy.py",line194,in _run_module_as_mainreturn_run_code(code,main_globals,None,File"/home/1/anaconda3/envs/sparsedrive/lib/python3.8/runpy.py",line87,in _run_codeexec(code,run_globals)File"/home/1/anaconda3/envs/sparsedrive/lib/python3.8/site-packages/torch/distributed/launch.py",line196,in<module>main()File"/home/1/anaconda3/envs/sparsedrive/lib/python3.8/site-packages/torch/distributed/launch.py",line192,in mainlaunch(args)File"/home/1/anaconda3/envs/sparsedrive/lib/python3.8/site-packages/torch/distributed/launch.py",line177,in launchrun(args)File"/home/1/anaconda3/envs/sparsedrive/lib/python3.8/site-packages/torch/distributed/run.py",line785,in runelastic_launch(File"/home/1/anaconda3/envs/sparsedrive/lib/python3.8/site-packages/torch/distributed/launcher/api.py",line134,in __call__returnlaunch_agent(self._config,self._entrypoint,list(args))File"/home/1/anaconda3/envs/sparsedrive/lib/python3.8/site-packages/torch/distributed/launcher/api.py",line250,in launch_agent raiseChildFailedError(torch.distributed.elastic.multiprocessing.errors.ChildFailedError:============================================================

这是因为torch2.0(1.8及以下不影响)不再使用torch.distributed.launch 启动,导致自动传入了 --local-rank 参数,而 train.py 无法解析。修改scripts/train.sh内容,启动方式为:

#!/bin/bash # 这是适配你需求的 stage1 训练脚本 # 核心:禁用分布式,用普通 python 命令启动,避免 local-rank 参数 export PYTHONPATH="$(dirname $0)/..":$PYTHONPATH # 定义训练配置和参数 CONFIG_FILE="projects/configs/sparsedrive_small_stage1.py"GPU_NUM=1# 单卡训练 DETERMINISTIC="--deterministic"WORK_DIR="./work_dirs/sparsedrive_stage1"# 可选:指定日志/模型保存目录 # 关键修改:用普通 python 启动,而非 dist_train.sh(避免分布式参数) python tools/train.py \ ${CONFIG_FILE}\--gpus ${GPU_NUM}\ ${DETERMINISTIC}\--launcher none \--work-dir ${WORK_DIR}# 可选,根据需要添加 # 定义训练配置和参数 CONFIG_FILE2="projects/configs/sparsedrive_small_stage2.py"GPU_NUM2=1# 单卡训练 DETERMINISTIC2="--deterministic"WORK_DIR2="./work_dirs/sparsedrive_stage2"# 可选:指定日志/模型保存目录 # 关键修改:用普通 python 启动,而非 dist_train.sh(避免分布式参数) python tools/train.py \ ${CONFIG_FILE2}\--gpus ${GPU_NUM2}\ ${DETERMINISTIC2}\--launcher none \--work-dir ${WORK_DIR2}# 可选,根据需要添加
#testsh scripts/test.sh
版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/5/9 7:42:32

AI时代下生产、分配与企业盈利的核心思考

在AI时代&#xff0c;信息处理效率得到了大幅提升&#xff0c;这直接推动了各类产品的生成总量显著增长。但需要注意的是&#xff0c;生产总量的进一步提升会受到销售环节的制约——若销售能力无法跟上生产节奏&#xff0c;总产出便会被限制。从生产逻辑来看&#xff0c;总产出…

作者头像 李华
网站建设 2026/5/9 7:39:14

防范SQL注入的SQL编码规范_禁用动态拼接字符串语句

String.format或拼接SQL是高危操作&#xff0c;因数据库驱动将拼接结果视为合法SQL执行&#xff0c;无法防御注入&#xff1b;必须用PreparedStatement等参数化查询&#xff0c;使用户输入仅作为数据而非语法结构处理。为什么 String.format 或 拼接 SQL 就算高危操作因为数据…

作者头像 李华
网站建设 2026/5/9 7:38:12

开源AI对话平台LibreChat:自部署、多模型整合与私有化部署指南

1. 项目概述&#xff1a;为什么你需要一个属于自己的开源AI对话平台&#xff1f;如果你和我一样&#xff0c;对AI对话应用充满热情&#xff0c;但又对主流闭源平台的数据隐私、功能限制或高昂成本感到困扰&#xff0c;那么“LibreChat”这个名字&#xff0c;你应该会立刻产生兴…

作者头像 李华
网站建设 2026/5/9 7:36:32

Hypnos-i1-8B基础教程:RoPE位置编码扩展对长文本推理的影响实测

Hypnos-i1-8B基础教程&#xff1a;RoPE位置编码扩展对长文本推理的影响实测 1. 模型简介与核心能力 Hypnos-i1-8B是一款专注于复杂推理任务的8B参数开源大模型&#xff0c;基于NousResearch/Hermes-3-Llama-3.1-8B微调而来。这款模型通过独特的量子噪声注入训练方法&#xff…

作者头像 李华
网站建设 2026/5/9 7:35:35

Qwen3-4B-Thinking入门必看:Gemini 2.5 Flash蒸馏模型本地化部署详解

Qwen3-4B-Thinking入门必看&#xff1a;Gemini 2.5 Flash蒸馏模型本地化部署详解 1. 模型概述 Qwen3-4B-Thinking-2507-Gemini-2.5-Flash-Distill是基于通义千问Qwen3-4B官方模型进行优化的版本。这个模型经过特殊训练&#xff0c;能够输出带有推理过程的思考链&#xff0c;特…

作者头像 李华