1.环境配置
操作 | 命令 | 版本 |
---|
检查cuda版本 | nvcc -V | 11.4 | 根据cuda版本下载pytorch(官网:https://pytorch.org/get-started/locally/) | pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu113 | 1.10.2 | 根据pytorch版本下载mmcv | pip install mmcv-full==1.4.6 -f https://download.openmmlab.com/mmcv/dist/cu113/torch1.10.0/index.html | 1.4.6 | 下载mmdetection(mmcv与mmdetection版本要对应:https://github.com/open-mmlab/mmdetection/blob/master/docs/zh_cn/get_started.md) | git clone https://github.com/open-mmlab/mmdetection.git cd mmdetection pip install -r requirements/build.txt pip install -e . | 2.23.0 |
2.测试环境是否安装正确
import os
import sys
from mmdet.apis import init_detector,inference_detector, show_result_pyplot
config_file = './configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py'
checkpoint_file = 'faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth'
device='cuda:0'
model = init_detector(config_file,checkpoint_file,device=device)
img = './demo/demo.jpg'
result = inference_detector(model, img)
show_result_pyplot(model, img, result, score_thr=0.3)
3.打印出你需要的config文件
python ./tools/misc/print_config.py ./configs/yolox/yolox_l_8x8_300e_coco.py>>yolox_l_8x8_300e_coco.txt
并将其修改为自己的config文件: ? 删除首行“Config:” ? load_from=预训练模型路径 ? resume_from=上一次训练的模型路径 ? num_classes=类别个数 ? ann_file=json文件路径 ? img_prefix=jpg文件路径 ? persistent_workers=False 不开多进程
-
修改/mmdet/datasets/builder.py文件: ? batch_size = 1 #134行 ? num_workers = 0 #135行 -
修改/mmdet/datasets/coco.py: ? CLASSES = (“person”,) ? PALETTE = (220, 20, 60) -
修改/mmdet/core/evaluation/class_names.py: ? return [‘person’]
4.开始训练
单gpu训练:
python ./tools/train.py ./configs/yolox/my_yolox_l.py --gpu-id 2
5.过程文件
其中含有my_yolox_l.py,faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth: 链接:https://pan.baidu.com/s/1rEqjj8kzFaRS_3ynXFX2MQ 提取码:4e34
|