本文档简要说明数据处理、模型构建、训练与测试方法。所有文件运行路径为./
。
Ubuntu1804LTS
3090*2
CUDA==11.0
cuDNN==8.0.5
(Anaconda)
conda create --name pytorch python==3.7
pip install -r requirements.txt
即可完成环境配置。
我们使用了基于yolov5
的改进版检测模型,其主要改进内容在于anchors,适配改动后的模型cfg文件存放为./models/yolov5x.cfg
。
- 数据清洗
经过我们人工清洗不合格的标注和大量重复的图片,得到新的xml文件于
./data/xml/
- 筛去小目标并转voc-xml为yolo-txt
python ./data/voc2yolo.py
- 加噪声
我们使用五种方式为图片添加随机噪声
python ./data/dataRefinforce.py
-
cp ./data/clearImgs/* ./data/images/train/ cp ./data/clearLabels/* ./data/labels/train/
- 预训练
nohup python -m torch.distributed.launch --nproc_per_node 2 train --batch-size 24 --img-size 512 --epochs 200 --data ./data/clear_voc.yaml --weights '' --hyp ./data/hyp.scratch.yaml --notest --cache --multi-scale > pretrain.log &
- 微调
nohup python -m torch.distributed.launch --nproc_per_node 2 train --batch-size 24 --img-size 512 --epochs 200 --data ./data/clear_voc.yaml --weights ./runs/train/exp/weights/best.pt --hyp ./data/hyp.finetune.yaml --notest --cache --multi-scale > finetune.log &
python detect.py --weights ./weights/yolov5_clear_noise.pt --source ..ships/a_test/pic/ --img-size 512 --conf-thres 0.25 --iou-thres 0.65 --device 0 --save-conf --save-result --augment
可得到结果json于./runs/detect/exp/