赞
踩
使用Internimage训练自己的数据集(目标检测)
https://github.com/OpenGVLab/InternImage/tree/master
1、基础设置文件所在位置:
D:\Project\InternImage-master\detection\configs\coco\dino_4scale_internimage_l_1x_coco_0.1x_backbone_lr.py
base = [
‘…/base/datasets/coco_detection.py’,
‘…/base/default_runtime.py’,
‘…/base/schedules/schedule_1x.py’,]
pretrained=‘预训练权重文件路径(最好是绝对路径)’ # 提前下载,可以找镜像
优化器、学习率、学习率的衰减的设置,最终在这里
2、epoch设置,保存
D:\Project\InternImage-master\detection\configs_base_\default_runtime.py
3、学习率、优化器设置
D:\Project\InternImage-master\detection\configs_base_\schedules\schedule_1x.py
4、数据集(训练集、验证集、测试集)设置 需要coco数据集,数据集格式见官网
–data
----coco
-------annotations
-------train2017
-------val2017
-------test2017
D:\Project\InternImage-master\detection\configs_base_\datasets\coco_detection.py
data_root = ‘coco数据集路径’
train
ann_file=data_root + ‘annotations/instances_train2017.json’,
img_prefix=data_root + ‘train2017/’,
val
test
5、batch_size和进程数
D:\Project\InternImage-master\detection\configs_base_\datasets\coco_detection.py
samples_per_gpu=2,
workers_per_gpu=2,
if dist:
# When model is :obj:DistributedDataParallel
,
# batch_size
of :obj:dataloader
is the
# number of training samples on each GPU.
batch_size = samples_per_gpu
num_workers = workers_per_gpu
else:
# When model is obj:DataParallel
# the batch size is samples on all the GPUS
batch_size = num_gpus * samples_per_gpu
num_workers = num_gpus * workers_per_gpu
6、训练代码
sh dist_train.sh configs/coco/mask_rcnn_internimage_t_fpn_1x_coco.py 8
configs/coco/配置文件 使用几个GPU
7、测试时运行代码
python test.py configs/coco/mask_rcnn_internimage_t_fpn_1x_coco.py checkpoint_dir/det/mask_rcnn_internimage_t_fpn_1x_coco.pth --eval bbox segm
“D:\Anaconda\envs\internimage\Lib\site-packages\mmdet\datasets\coco.py” # 修改class具体为什么,一个类别的话需要加逗号,如(num_class1,)
“D:\Anaconda\envs\internimage\Lib\site-packages\mmdet\core\evaluation\class_names.py” 修改def coco_classes():中的类别,一个类别的话,需要加逗号
https://mmcv.readthedocs.io/zh-cn/1.x/faq.html
8、GPU显存不够,调小batch_size 和图片裁剪大小,还可以更改预训练模型,更改较小的预训练模型,如更改
sh dist_train.sh configs/coco/dino_4scale_internimage_l_1x_coco_0.1x_backbone_lr.py 1 为sh dist_train.sh configs/coco/dino_4scale_internimage_t_1x_coco_layer_wise_lr.py 1 (训练时再终端输入该命令)
9、sh命令,需要安装Git环境
.sh脚本就是执行train.py文件 以及端口号信息
10、环境问题
conda create -n internimage python=3.7 -y
conda activate internimage
查看自己的CUDA版本号(nvidia-smi,安装版本最好低于自己查看的版本)如:
pip install torch1.11.0+cu113 torchvision0.12.0+cu113 -f https://download.pytorch.org/whl/torch_stable.html
pip install -U openmim
mim install mmcv-full1.5.0
pip install timm0.6.11 mmdet==2.28.1
pip install opencv-python termcolor yacs pyyaml scipy
cd ./ops_dcnv3
sh ./make.sh
python test.py
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。