TYS的博客

算法小白努力学习中

0%

mmdetection网络训练

mmdetection训练

如何制作数据集https://github.com/spytensor/prepare_detection_dataset

将labelme格式的数据转化为coco格式数据,需要对文件进行改写。

// 修改类别,修改image字段 修改area

1
annotation['area'] = annotation['bbox'][2]  *  annotation['bbox'][3]

json编辑器dadroit

通过目录的软连接将数据创建到data文件夹下

https://blog.csdn.net/duanyajun987/article/details/97659685

修改mmdetection/mmdet/datasets/coco.py CLASSES

mmdetection/mmdet/core/evaluation/class_names.py 修改

1
2
3
4
def coco_classes():
return [
'Prim', 'Lym', 'Mono', 'Plas', 'Red','Promy','Myelo','Late','Rods','Lobu','Eosl'
]

修改configs/models/retinanet_r50_fpn.py

1
num_classes=11,

训练数据集

1
python tools/train.py configs/retinanet/retinanet_r50_fpn_1x_coco.py  --work-dir work_dirs --resume-from work_dirs/latest.pth --gpus 2

多卡训练

1
bash ./tools/dist_train.sh  configs/retinanet/retinanet_r50_fpn_1x_coco.py  2  --work-dir work_dirs --resume-from work_dirs/latest.pth

查看显卡使用情况

1
watch -n 1 -d nvidia-smi

真正的训练文件mmdet/apis/train.py

修改epoch configs/_base_/schedules/schedules_1x.pyrunner = dict(type='EpochBasedRunner', max_epochs=240)修改epoch数量

修改batchsizeconfigs/datasets/coco_detection.py samples_per_gpu参数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
data = dict(
samples_per_gpu=2,
workers_per_gpu=2,
train=dict(
type=dataset_type,
ann_file=data_root + 'annotations/instances_train2017.json',
img_prefix=data_root + 'train2017/',
pipeline=train_pipeline),
val=dict(
type=dataset_type,
ann_file=data_root + 'annotations/instances_val2017.json',
img_prefix=data_root + 'val2017/',
pipeline=test_pipeline),
test=dict(
type=dataset_type,
ann_file=data_root + 'annotations/instances_val2017.json',
img_prefix=data_root + 'val2017/',
pipeline=test_pipeline))

test

1
python tools/test.py configs/retinanet/retinanet_r50_fpn_1x_coco.py checkpoints/retinanet_r50_fpn_1x_coco_20200130-c2398f9e.pth --show
1
python tools/test.py configs/retinanet/retinanet_r50_fpn_1x_coco.py work_dirs/latest.pth --out test_result/latest.pkl --eval bbox --show-dir detect_results

mmdetection 结果炫酷可视化

TSNE

热力图(好看的colorbarhttps://www.cnblogs.com/zb-ml/p/13561449.html)

docker环境

1
docker run -dit --name sty_cell --gpus  all   -p 10022:22 --shm-size=16g  -v /mnt/sda/sty/data:/Data  nvidia/cuda:11.2.2-cudnn8-devel-ubuntu18.04

创建docker环境,安装anaconda,安装mmcv mmdet

训练faster-rcnn

修改 /mmdet/datasets/coco.py

1
CLASSES = ( 'Prim', 'Lym', 'Mono', 'Plas', 'Red','Promy','Myelo','Late','Rods','Lobu','Eosl')

修改config/_base_/models/faster_rcnn_r50_fpn.py

1
num_classes=11

指定GPU训练数据集

1
CUDA_VISIBLE_DEVICES=1 python tools/train.py configs/faster_rcnn/faster_rcnn_r50_fpn_2x_coco.py  --work-dir work_dir/faster_rcnn