本仓库实现 将https://github.com/Sense-X/Co-DETR 迁移到mindspore,进行训练和推理验证
| NPU软件配置项 | 版本信息 |
|---|---|
| Python | 3.10 |
| 驱动&固件 | 25.2 |
| CANN | 8.3.RC1 |
| mindspore | 2.6.0 |
创建并激活 python 3.10 conda环境:
conda create -n codetr python=3.10
conda activate codetr安装mindpore
参考 https://www.mindspore.cn/install 完成安装和验证安装其他依赖:
pip install sympy packaging pillow protobuf asttokens astunparse opencv-python opencv-python-headless pycocotools tqdm pyyaml decorator attrs opencv-contrib-python-headless根据co-detr官网中的Modezoo指引(https://github.com/Sense-X/Co-DETR)下载pth权重(co_dino_5scale_swin_large_16e_o365tococo.pth),按如下路径放置
Co-DETR
└── weight
└── co_dino_5scale_swin_large_16e_o365tococo.pth下载coco2017 数据集,按如下路径存放
Co-DETR
└── datasets
└── coco2017
├── annotations
│ ├── instances_train2017.json
│ └── instances_val2017.json
├── train2017
└── val2017 先将官方预训练权重转化为mindpore支持的格式 检查 pt2ckpt.py 脚本中的输入pth权重路径后最后保存的权重路径无误后,执行:
python pt2ckpt.py执行成功后,默认会在weight目录,生成一个.ckpt 文件
Co-DETR
└── weight
└── co_dino_5scale_swin_large_16e_o365tococo.pth
└── co_dino_5scale_swin_large_16e_o365tococo.ckptcoco_path: ./datasets/coco2017 # coco数据集路径,确保和实际路径一致
pretrain_path: ./weight/co_dino_5scale_swin_large_16e_o365tococo.ckpt # 预训练权重路径,确保和实际路径一致bash train.sh 8 # 8 卡训练
bash train.sh # 单卡训练训练后将会在workdirs下按日期生成文件夹,存放权重和loss数据
test_model_path: ./work_dirs/2025_12_10-10_10_58/codetr_epoch015_rank0.ckpt # workdirs目录下训练生成好的权重路径bash test.sh 8 # 8 npus
bash test.sh # single npu训练精度:16epoch,mAP 62.1%
训练性能:910B3:2.5s/step
推理性能:910B1:0.77s/step