DETR-Object detection配置教程
0. github下载为zip压缩包,解压到你的工作目录下
Object Detection with DETR : A minimal implementation DEMO点击此处
1. Anaconda环境配置
- 创建detr环境
conda create -n detr python=3.8
conda activate detr
cd D:\Coding\AnacondaProject\detr-main #进入detr-main目录
- 安装pytorch 1.5+ 和torchvision 0.6+
conda install -c pytorch pytorch torchvision
- 安装pycocotools和scipy,用于在COCO数据集上进行evaluation及训练
conda install cython scipy
pip install -U 'git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI' #本机测试不行
pip install pycocotools #使用这条命令安装pycocotools
- (可选)如果想使用panoptic
pip install git+https://github.com/cocodataset/panopticapi.git
2. 数据准备
Download and extract COCO 2017 train and val images with annotations from http://cocodataset.org. We expect the directory structure to be the following:
path/to/coco/
annotations/ # annotation json files
train2017/ # train images
val2017/ # val images
3. 训练
在单节点8个gpu上对基线DETR训练300个epochs:
python -m torch.distributed.launch --nproc_per_node=8 --use_env main.py --coco_path /path/to/coco
A single epoch takes 28 minutes, so 300 epoch training takes around 6 days on a single machine with 8 V100 cards. To ease reproduction of our results we provide results and training logs for 150 epoch schedule (3 days on a single machine), achieving 39.5/60.3 AP/AP50.
4. 评估
在COCO val 5k用一个GPU对DETR R50进行评估:
python main.py --batch_size 2 --no_aux_loss --eval --resume https://dl.fbaipublicfiles.com/detr/detr-r50-e632da11.pth --coco_path /path/to/coco
5. 多节点训练
分布式训练可以使用Slurm和submitit
pip install submitit
在4个节点上对基线模型DETR-6-6训练300 epochs:
python run_with_submitit.py --timeout 3000 --coco_path /path/to/coco