文件最后提交记录最后更新时间
!6042 [built-in][PyTorch][MatrixVT] enable fp16 and delete lr sheduler Merge pull request !6042 from 孙依然/master 2 年前
!6042 [built-in][PyTorch][MatrixVT] enable fp16 and delete lr sheduler Merge pull request !6042 from 孙依然/master 2 年前
!5768 [built-in][Pytorch][MatrixVT] Add MatrixVT performance optimization points * Model adaptation * Add performance optimization points 2 年前
!6810 【MatrixVT】性能脚本后缀修改,acc改为perf Merge pull request !6810 from huangju1993/master 1 年前
!5761 [built-in][Pytorch][MatrixVT]Submit MatrixVT source code * MatrixVT源码提交 2 年前
!6074 PyTorch 2.2 版本依赖配套更新 Merge pull request !6074 from Chai/master 2 年前
!6349 PyTorch 2.3 版本依赖配套更新 Merge pull request !6349 from 周嘉益/master 1 年前
!6574 PyTorch 2.4 版本依赖配套更新 Merge pull request !6574 from 周嘉益/pt24 1 年前
!5761 [built-in][Pytorch][MatrixVT]Submit MatrixVT source code * MatrixVT源码提交 2 年前
fix link validity Co-authored-by: frozenleaves<914814442@qq.com> # message auto-generated for no-merge-commit merge: !7517 merge master into master fix link validity Created-by: frozenn Commit-by: frozenleaves Merged-by: ascend-robot Description: ## Motivation Please describe the motivation of this PR and the goal you want to achieve through this PR. ## Modification Please briefly describe what modification is made in this PR. ## Self-test (Optional) If modifications to this PR may cause/fix function/accuracy/performance DTSs/issues, a self-inspection record needs to be attached. ## BC-breaking (Optional) If there are compatibility issues, such as dependencies on cann/torch_npu versions, they need to be explained in the PR. ## Checklist **Before PR**: - [ ] The new code needs to comply with the Clean Code specification. - [ ] The PR content is self-checked, and the expression can be clear and the writing standardized **After PR**: - [ ] CLA has been signed and all committers have signed the CLA in this PR. - [ ] The ci-pipeline is passed, Code Check is passed. See merge request: Ascend/ModelZoo-PyTorch!75171 个月前
fix link validity Co-authored-by: frozenleaves<914814442@qq.com> # message auto-generated for no-merge-commit merge: !7517 merge master into master fix link validity Created-by: frozenn Commit-by: frozenleaves Merged-by: ascend-robot Description: ## Motivation Please describe the motivation of this PR and the goal you want to achieve through this PR. ## Modification Please briefly describe what modification is made in this PR. ## Self-test (Optional) If modifications to this PR may cause/fix function/accuracy/performance DTSs/issues, a self-inspection record needs to be attached. ## BC-breaking (Optional) If there are compatibility issues, such as dependencies on cann/torch_npu versions, they need to be explained in the PR. ## Checklist **Before PR**: - [ ] The new code needs to comply with the Clean Code specification. - [ ] The PR content is self-checked, and the expression can be clear and the writing standardized **After PR**: - [ ] CLA has been signed and all committers have signed the CLA in this PR. - [ ] The ci-pipeline is passed, Code Check is passed. See merge request: Ascend/ModelZoo-PyTorch!75171 个月前
!5761 [built-in][Pytorch][MatrixVT]Submit MatrixVT source code * MatrixVT源码提交 2 年前
!6042 [built-in][PyTorch][MatrixVT] enable fp16 and delete lr sheduler Merge pull request !6042 from 孙依然/master 2 年前
!5768 [built-in][Pytorch][MatrixVT] Add MatrixVT performance optimization points * Model adaptation * Add performance optimization points 2 年前
README.md

当前仓已不再维护,请跳转至https://gitcode.com/ascend/DrivingSDK/tree/master/model_examples/MatrixVT

MatrixVT for PyTorch

目录

简介

模型介绍

MatrixVT是一个基于Transformer结构的BEV 3D检测模型,没有定制化算子。针对目前BEV中更有优势的Lift-Splat类方法中关键模块(Vision Transformation),MatrixVT实现了非常优雅的优化,在保持模型性能(甚至略微提高)的同时,能大幅降低计算量和内存消耗。

支持任务列表

本仓已经支持以下模型任务类型

模型 任务列表 是否支持
MatrixVT 训练

代码实现

  • 参考实现:

    url=https://github.com/Megvii-BaseDetection/BEVDepth/
    commit_id=d78c7b58b10b9ada940462ba83ab24d99cae5833
    
  • 适配昇腾 AI 处理器的实现:

    url=https://gitcode.com/ascend/ModelZoo-PyTorch.git
    code_path=PyTorch/built-in/autonoumous_driving/MatrixVT/
    

MatrixVT

准备训练环境

安装模型环境

  • 推荐参考配套资源文档使用最新的配套版本。

    表 1 版本配套表

    软件 版本 安装指南
    Driver AscendHDK 24.1.RC3 驱动固件安装指南
    Firmware AscendHDK 24.1.RC3
    CANN CANN 8.0.RC3 CANN 软件安装指南
    PyTorch 2.1.0 Ascend Extension for PyTorch 配置与安装
    torch_npu release v6.0.rc3
  • 三方库依赖如下表所示。

    表 2 三方库依赖表

    三方库 支持版本
    PyTorch 2.1.0
    TorchVision 0.16.0
    NumPy 1.23.5
    pytorch-lightning 1.6.5
    mmdet3d 1.0.0rc4
    mmcv 1.7.1, 1.7.2
  • 环境准备指导。

    请参考《Pytorch框架训练环境准备》。

  • 安装依赖。

    pip install -r requirements.txt        # PyTorch 2.1版本
    

    手动安装指定三方库:

  • 安装mmcv==1.x(如果环境中有mmcv,请先卸载再执行以下步骤)。

    git clone -b 1.x https://github.com/open-mmlab/mmcv
    cd mmcv
    
    安装完成后将源码根目录下面code_for_change中的setup.py替换到mmcv中的setup.py
    
    MMCV_WITH_OPS=1 pip install -e . -v
    
    安装完成mmcv之后,进入{mmcv_install_path}/mmcv/ops/deform_conv.py文件夹,修改deform_conv.py文件,修改内容如下:
    导入torch_npu
    修改第56行,将torch.npu_deformable_conv2dbk修改为torch_npu.npu_deformable_conv2dbk
    
    修改modulated_deform_conv.py,修改内容如下:
    导入torch_npu
    修改第59行,将torch.npu_deformable_conv2d修改为torch_npu.npu_deformable_conv2d
      
    cd ../
    
  • 安装mmdet3d==1.0.0rc4(如果环境中有mmdet,请先卸载再执行以下步骤)。

    pip install mmdet3d==1.0.0rc4
    

返回模型根目录

python setup.py develop

源码替换

pip show pytorch_lightning

找到pytorch_lightning的安装路径,然后将源码根目录下面code_for_change中的文件替换掉pytorch_lightning安装路径下对应的文件。

cp ./code_for_change/subprocess_script.py {pytorch_lightning_install_path}/strategies/launchers/subprocess_script.py
cp ./code_for_change/training_epoch_loop.py {pytorch_lightning_install_path}/loops/epoch/training_epoch_loop.py
cp ./code_for_change/types.py {pytorch_lightning_install_path}/utilities/types.py
cp ./code_for_change/accelerator_connector.py {pytorch_lightning_install_path}/trainer/connectors/accelerator_connector.py

准备数据集

  1. 请用户自行获取并解压nuScenes数据集,并将数据集的路径软链接到 ./data/

    ln -s [nuscenes root] ./data/
    
  2. 在源码根目录下进行数据集预处理。

    python scripts/gen_info.py
    python scripts/gen_depth_gt.py
    

    参考数据集结构如下:

     MatrixVT for PyTorch
     ├── data
     │   ├── nuScenes
     │   │   ├── maps
     │   │   ├── samples
     │   │   ├── sweeps
     │   │   ├── v1.0-test
     |   |   ├── v1.0-trainval
    

    说明:
    该数据集的训练过程脚本只作为一种参考示例。

快速开始

训练任务

本任务主要提供混精fp168卡训练脚本。

开始训练

  1. 进入源码根目录。

    cd /${模型文件夹名称}
    
  2. 运行训练脚本。

    该模型支持单机8卡训练。

    • 单机8卡训练
    bash ./test/train_full_8p.sh # 8卡精度,混精fp16
    bash ./test/train_performance_8p.sh # 8卡性能,混精fp16
    

    注:当前配置下,不需要修改train_full_8p.sh中的ckpt路径,如果涉及到epoch的变化,请用户根据路径自行配置ckpt。

    模型训练脚本参数说明如下。

    matrixvt_bev_depth_lss_r50_256x704_128x128_24e_ema.py
    --seed                              // 随机种子
    --learning_rate                     // 学习率
    --max_epoch                         // 最大迭代回合数
    --amp_backend                       // 混精策略
    --gpus                              // 卡数
    --precision                         // 训练精度模式
    --batch_size_per_device             // 每张卡的批大小
    

训练结果

精度
芯片 卡数 mAP mATE mASE mAOE mAVE mAAE NDS batch_size AMP_Type Torch_Version
竞品A 8p 0.3245 0.6546 0.2712 0.5572 0.8833 0.2288 0.4027 64 fp16 2.1
Atlas 800T A2 8p 0.3247 0.6555 0.2716 0.5251 0.8661 0.2316 0.4073 64 fp16 2.1
性能
芯片 卡数 FPS Each epoch time batch_size AMP_Type Torch_Version
竞品A 8p 56 0.65 h 64 fp16 2.1
Atlas 800T A2 8p 45 0.81 h 64 fp16 2.1

说明:上表为历史数据,仅供参考。2024年12月31日更新的性能数据如下:

NAME 精度类型 FPS
8p-竞品 FP16 56
8p-Atlas 900 A2 PoDc FP16 56

公网地址说明

代码涉及公网地址参考 public_address_statement.md 及 README.md

变更说明

2023.11.09:首次发布。

FAQ

  1. 报错scikit_learning.libs/libgomp-d22c30c5.so.1.0.0: cannot allocate memory in static TLS block的问题,解决方案为:

    # 手动导入环境变量
    export LD_PRELOAD={libgomp-d22c30c5.so.1.0.0_path}/libgomp-d22c30c5.so.1.0.0:$LD_PRELOAD
    
  2. 如果使用pip安装mmdet3d失败,请采用源码安装的方式。源码下载地址为:

    https://github.com/open-mmlab/mmdetection3d/releases/tag/v1.0.0rc4
    

    请下载链接中的源码压缩包,自行手动安装。同时修改mmdet3d的源码,进入mmdet3d的安装路径,修改内容有:

    1) cd /${mmdet3d-1.0.0rc4的安装路径}/mmdet3d/
      将__init__.py中的文件第41行mmcv_maximum_version = '1.7.0'修改为mmcv_maximum_version = '1.7.2'
    2) cd /${mmdet3d-1.0.0rc4的安装路径}/requirements/
      删除runtime.txt中的numba==0.53.0这一行。
    

    然后执行:

    cd /${mmdet3d-1.0.0rc4的安装路径}/
    pip install -v -e .