涨分神器

您所在的位置:网站首页 win10自动搜索文件 涨分神器

涨分神器

2023-04-18 14:24| 来源: 网络整理| 查看: 265

0 项目背景

目标检测和实例分割是迄今为止计算机视觉中最重要的应用领域。然而,小物体的检测和大图像的推理仍然是实际使用中的主要问题。

比如当图像分辨率很大且样本中小目标居多时,如果reshape成小图再送进网络训练的话,目标会变得非常小,检测模型识别难度很大。

然而,直接大图训练GPU显存又顶不住,太大的原图会消耗太多的cpu时间,导致极度拖慢训练时间,而且推理速度会很慢。

如果我们可以通过离线切图的形式,把原图按一定的宽高,切成很多个小图进行训练,就能够将上面这种复杂的大图小目标检测任务,转换成较为普通的目标检测任务,从而提高小图上小目标的检测效果。接着,通过拼图与后处理,将子图预测结果再合并成大图,得到完整的大图推理结果。

百度飞桨针对上面这种大图小目标检测的典型场景,提供了PP-YOLOE Smalldet一键实现切图配置与训练。

详细文档可参考:PP-YOLOE Smalldet 检测模型。

那么,在实际业务场景中,切图拼图的目标检测任务究竟表现如何?本文就以正在进行的兴智杯国产开发框架工程化应用赛:齿轮瑕疵检测任务为例,验证自动切图训练在真实场景的表现。

1 环境准备 1.1 数据集准备

数据集的分析和准备过程在项目 兴智杯国产开发框架工程化应用赛:齿轮瑕疵检测基线中有详细的介绍,这里就不再赘述。

总体结论就是,齿轮瑕疵数据集存在密集小目标,但也有大面积的瑕疵目标。因此,正好可以被我们拿来练练手,比对下切图前后的训练效果。

# 数据集解压缩:读者可以将数据集上传到AI Studio,再根据实际项目的具体路径,解压数据集 # 注意由于数据集文件名是中文,解压的时候要指定编码(也可以本地对数据集改名后再上传) !unzip -O GBK data/data163113/齿轮检测数据集.zip -d ./data/ # 整理数据集结构,移除脏数据 !mv data/齿轮检测数据集/train/train_coco.json data/齿轮检测数据集/ !rm data/齿轮检测数据集/train/Thumbs.db # 引入PaddleX !pip install paddlex # 安装切图工具 !pip install sahi # 组织数据目录 !mkdir MyDataset !mkdir MyDataset/JPEGImages !mv data/齿轮检测数据集/train/*.jpg MyDataset/JPEGImages/ !mv data/齿轮检测数据集/train_coco.json MyDataset/annotations.json # 按比例切分数据集 !paddlex --split_dataset --format COCO --dataset_dir MyDataset --val_value 0.1 --test_value 0.0 1.2 训练环境准备

由于PP-YOLOE还在快速迭代中,因此,对框架的稳定性有一定的要求,PaddlePaddle的框架不要选择最新版。本文使用的单卡训练环境如下:

框架版本:PaddlePaddle 2.2.2CUDA Version: 11.2模型库版本:PaddleDetection(release/2.5分支) !git clone https://gitee.com/paddlepaddle/PaddleDetection.git 正克隆到 'PaddleDetection'... remote: Enumerating objects: 27803, done.[K remote: Counting objects: 100% (8273/8273), done.[K remote: Compressing objects: 100% (3341/3341), done.[K 接收对象中: 17% (4876/27803), 14.54 MiB | 1.33 MiB/s %cd PaddleDetection /home/aistudio/PaddleDetection # 切换到release/2.5分支 !git checkout release/2.5 M configs/smalldet/_base_/visdrone_sliced_640_025_detection.yml M configs/smalldet/ppyoloe_crn_l_80e_sliced_visdrone_640_025.yml M configs/smalldet/ppyoloe_crn_l_80e_sliced_visdrone_640_025_slice_infer.yml M tools/box_distribution.py 已经位于 'release/2.5' 您的分支与上游分支 'origin/release/2.5' 一致。 1.3 切图数据准备 1.3.1 统计数据集分布

在切图前,我们首先需要统计所用数据集标注框的平均宽高占图片真实宽高的比例分布:

--json_path :待统计数据集COCO 格式 annotation 的json文件路径--out_img :输出的统计分布图路径 # PaddleDetection中box_distribution.py文件有点小bug,这里先进行修复 !cp ../box_distribution.py tools/box_distribution.py !python tools/box_distribution.py --json_path /home/aistudio/MyDataset/annotations.json --out_img box_distribution.jpg /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/numpy/core/fromnumeric.py:3420: RuntimeWarning: Mean of empty slice. out=out, **kwargs) /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/numpy/core/_methods.py:188: RuntimeWarning: invalid value encountered in double_scalars ret = ret.dtype.type(ret / rcount) Median of ratio_w is 0.050386904761904765 Median of ratio_h is 0.0305 all_img with box: 1399 all_ann: 28575 Distribution saved as box_distribution.jpg Figure(640x480)

在这里插入图片描述

注意:

当原始数据集全部有标注框的图片中,有1/2以上的图片标注框的平均宽高与原图宽高比例小于0.04时,建议进行切图训练。

所以根据上面的说明,齿轮瑕疵检测这个数据集其实介于“可切可不切”之间。当然,我们可以继续试验下,看看切图后能达到的效果。

1.3.2 基于SAHI切图

针对需要切图的数据集,使用SAHI库进行切分:

--image_dir:原始数据集图片文件夹的路径--json_path:原始数据集COCO格式的json标注文件的路径--output_dir:切分后的子图及其json标注文件保存的路径--slice_size:切分以后子图的边长尺度大小(默认切图后为正方形)--overlap_ratio:切分时的子图之间的重叠率以上述代码为例,切分后的子图文件夹与json标注文件共同保存在MyDataset/IMG_sliced文件夹下,比如训练集图片和标注就命名为train_images_640_025、train_images_640_025.json。 !mkdir /home/aistudio/MyDataset/IMG_sliced # 对训练集标注进行切图 !python tools/slice_image.py --image_dir /home/aistudio/MyDataset/JPEGImages --json_path /home/aistudio/MyDataset/train.json --output_dir /home/aistudio/MyDataset/IMG_sliced --slice_size 640 --overlap_ratio 0.25 # 对验证集标注进行切图 !python tools/slice_image.py --image_dir /home/aistudio/MyDataset/JPEGImages --json_path /home/aistudio/MyDataset/val.json --output_dir /home/aistudio/MyDataset/IMG_sliced --slice_size 640 --overlap_ratio 0.25 2 模型训练 2.1 拼图模型选型

PaddleDetection团队提供的基于PP-YOLOE的检测模型,以及提供了一套使用SAHI(Slicing Aided Hyper Inference)工具切图和拼图的方案,其效果如下:

模型数据集SLICE_SIZEOVERLAP_RATIO类别数mAPval0.5:0.95APval0.5下载链接配置文件PP-YOLOE-lVisDrone-DET6400.251029.748.5下载链接配置文件PP-YOLOE-l (Assembled)VisDrone-DET6400.251037.259.4下载链接配置文件

Assembled表示自动切图和拼图后模型的表现,从中我们可以看出,mAP较原图预测有了非常显著的提升,因此,接下来就基于PP-YOLOE-l,看看自动切图和拼图后模型在齿轮瑕疵检测数据集上的表现。

2.2 模型训练

毫无疑问,切图后模型的训练是要基于切图数据集的,配置如下:

TrainDataset: !COCODataSet image_dir: /home/aistudio/MyDataset/IMG_sliced/train_images_640_025 anno_path: /home/aistudio/MyDataset/IMG_sliced/train_640_025.json dataset_dir: /home/aistudio/MyDataset data_fields: ['image', 'gt_bbox', 'gt_class', 'is_crowd'] EvalDataset: !COCODataSet image_dir: /home/aistudio/MyDataset/IMG_sliced/val_images_640_025 anno_path: /home/aistudio/MyDataset/IMG_sliced/val_640_025.json dataset_dir: /home/aistudio/MyDataset # 覆盖配置文件 !cp ../ppyoloe_crn_l_80e_sliced_visdrone_640_025.yml configs/smalldet/ppyoloe_crn_l_80e_sliced_visdrone_640_025.yml !cp ../visdrone_sliced_640_025_detection.yml configs/smalldet/_base_/visdrone_sliced_640_025_detection.yml # 开始训练 !python tools/train.py -c configs/smalldet/ppyoloe_crn_l_80e_sliced_visdrone_640_025.yml --use_vdl=True --vdl_log_dir=./sliced_visdrone/ --eval

切图训练时间是否一定比原图训练时间长?这个要视情况而定。

因为切图后训练数据集的数据量虽然大幅增加了,但是切图后输入图片可以减小分辨率(从而增大batchsize)。当然通常来说,切图训练时间要比原图训练时间要长一些。

在原图训练的PPYOLOE:又快又好的小目标检测训练与部署实现中,10个epoch训练耗时在60min左右;切图训练则需要48min左右,因为增大了batchsize,训练效率反而提高了。

而且,切图模型收敛速度相较于原图训练,明显快了很多。

在这里插入图片描述

在这里插入图片描述

3 模型评估

我们对训练30个epoch后,切图模型的效果进行一下评估。

3.1 子图评估

对于子图评估和原图评估,差别仅仅在于验证集路径的配置:

子图评估 配置切图后的子图存放目录和子图验证集标注文件 原图评估 配置原图存放目录和验证集标注文件 # 训练30个epoch后,子图评估 !python tools/eval.py -c configs/smalldet/ppyoloe_crn_l_80e_sliced_visdrone_640_025.yml -o weights=output/ppyoloe_crn_l_80e_sliced_visdrone_640_025/best_model.pdparams /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/vision/transforms/functional_pil.py:36: DeprecationWarning: NEAREST is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.NEAREST or Dither.NONE instead. 'nearest': Image.NEAREST, /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/vision/transforms/functional_pil.py:37: DeprecationWarning: BILINEAR is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.BILINEAR instead. 'bilinear': Image.BILINEAR, /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/vision/transforms/functional_pil.py:38: DeprecationWarning: BICUBIC is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.BICUBIC instead. 'bicubic': Image.BICUBIC, /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/vision/transforms/functional_pil.py:39: DeprecationWarning: BOX is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.BOX instead. 'box': Image.BOX, /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/vision/transforms/functional_pil.py:40: DeprecationWarning: LANCZOS is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.LANCZOS instead. 'lanczos': Image.LANCZOS, /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/vision/transforms/functional_pil.py:41: DeprecationWarning: HAMMING is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.HAMMING instead. 'hamming': Image.HAMMING Warning: Unable to use OC-SORT, please install filterpy, for example: `pip install filterpy`, see https://github.com/rlabbe/filterpy Warning: import ppdet from source directory without installing, run 'python setup.py install' to install ppdet firstly W0906 00:49:25.085027 31458 device_context.cc:447] Please NOTE: device: 0, GPU Compute Capability: 7.0, Driver API Version: 11.2, Runtime API Version: 10.1 W0906 00:49:25.089991 31458 device_context.cc:465] device: 0, cuDNN Version: 7.6. loading annotations into memory... Done (t=0.02s) creating index... index created! [09/06 00:49:30] ppdet.utils.checkpoint INFO: Finish loading model weights: output/ppyoloe_crn_l_80e_sliced_visdrone_640_025/best_model.pdparams [09/06 00:49:30] ppdet.engine INFO: Eval iter: 0 [09/06 00:49:37] ppdet.engine INFO: Eval iter: 100 [09/06 00:49:44] ppdet.engine INFO: Eval iter: 200 [09/06 00:49:51] ppdet.engine INFO: Eval iter: 300 [09/06 00:49:58] ppdet.engine INFO: Eval iter: 400 [09/06 00:50:05] ppdetrics.metrics INFO: The bbox result is saved to bbox.json. loading annotations into memory... Done (t=0.03s) creating index... index created! [09/06 00:50:05] ppdetrics.coco_utils INFO: Start evaluate... Loading and preparing results... DONE (t=3.95s) creating index... index created! Running per image evaluation... Evaluate annotation type *bbox* DONE (t=13.39s). Accumulating evaluation results... DONE (t=1.71s). Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.490 Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=100 ] = 0.816 Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=100 ] = 0.522 Average Precision (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.459 Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.543 Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.611 Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 1 ] = 0.130 Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 10 ] = 0.481 Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.639 Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.535 Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.688 Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.874 [09/06 00:50:25] ppdet.engine INFO: Total sample number: 812, averge FPS: 27.543498235955227 3.2 原图评估 !cp ../ppyoloe_crn_l_80e_sliced_visdrone_640_025-Copy1.yml configs/smalldet/ppyoloe_crn_l_80e_sliced_visdrone_640_025-Copy1.yml # 训练30个epoch后,原图评估 !python tools/eval.py -c configs/smalldet/ppyoloe_crn_l_80e_sliced_visdrone_640_025-Copy1.yml -o weights=output/ppyoloe_crn_l_80e_sliced_visdrone_640_025/best_model.pdparams /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/vision/transforms/functional_pil.py:36: DeprecationWarning: NEAREST is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.NEAREST or Dither.NONE instead. 'nearest': Image.NEAREST, /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/vision/transforms/functional_pil.py:37: DeprecationWarning: BILINEAR is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.BILINEAR instead. 'bilinear': Image.BILINEAR, /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/vision/transforms/functional_pil.py:38: DeprecationWarning: BICUBIC is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.BICUBIC instead. 'bicubic': Image.BICUBIC, /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/vision/transforms/functional_pil.py:39: DeprecationWarning: BOX is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.BOX instead. 'box': Image.BOX, /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/vision/transforms/functional_pil.py:40: DeprecationWarning: LANCZOS is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.LANCZOS instead. 'lanczos': Image.LANCZOS, /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/vision/transforms/functional_pil.py:41: DeprecationWarning: HAMMING is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.HAMMING instead. 'hamming': Image.HAMMING Warning: Unable to use OC-SORT, please install filterpy, for example: `pip install filterpy`, see https://github.com/rlabbe/filterpy Warning: import ppdet from source directory without installing, run 'python setup.py install' to install ppdet firstly W0906 00:54:40.913517 32345 device_context.cc:447] Please NOTE: device: 0, GPU Compute Capability: 7.0, Driver API Version: 11.2, Runtime API Version: 10.1 W0906 00:54:40.918522 32345 device_context.cc:465] device: 0, cuDNN Version: 7.6. loading annotations into memory... Done (t=0.02s) creating index... index created! [09/06 00:54:45] ppdet.utils.checkpoint INFO: Finish loading model weights: output/ppyoloe_crn_l_80e_sliced_visdrone_640_025/best_model.pdparams [09/06 00:54:46] ppdet.engine INFO: Eval iter: 0 [09/06 00:54:55] ppdetrics.metrics INFO: The bbox result is saved to bbox.json. loading annotations into memory... Done (t=0.01s) creating index... index created! [09/06 00:54:55] ppdetrics.coco_utils INFO: Start evaluate... Loading and preparing results... DONE (t=0.65s) creating index... index created! Running per image evaluation... Evaluate annotation type *bbox* DONE (t=5.27s). Accumulating evaluation results... DONE (t=0.23s). Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.389 Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=100 ] = 0.733 Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=100 ] = 0.361 Average Precision (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.213 Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.384 Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.567 Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 1 ] = 0.050 Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 10 ] = 0.276 Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.520 Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.299 Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.505 Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.679 [09/06 00:55:01] ppdet.engine INFO: Total sample number: 141, averge FPS: 17.53671755623329 3.3 子图拼图评估

对于子图拼图评估,需要修改验证集的标注文件路径为原图标注文件,然后配置设置如下:

EvalDataset: !SlicedCOCODataSet image_dir: VisDrone2019-DET-val anno_path: val.json dataset_dir: dataset/visdrone sliced_size: [640, 640] overlap_ratio: [0.25, 0.25]

需要注意的是,子图拼图评估耗时可能非常长,它取决于模型权重文件的大小。同时,在配置子图拼图评估是,需要用SlicedCOCODataSet替代COCODataSet,并且配置切图训练时的sliced_size和overlap_ratio参数:

设置--slice_infer表示切图预测并拼装重组结果,如果不使用则不写,注意需要确保EvalDataset的数据集类是选用的SlicedCOCODataSet而不是COCODataSet;设置--slice_size表示切图的子图尺寸大小,设置--overlap_ratio表示子图间重叠率,可以自行修改选择合适的子图尺度sliced_size和子图间重叠率overlap_ratio。 !cp ../ppyoloe_crn_l_80e_sliced_visdrone_640_025_slice_infer.yml configs/smalldet/ppyoloe_crn_l_80e_sliced_visdrone_640_025_slice_infer.yml

执行命令时,需要关注下面这些参数的设置:

设置--combine_method表示子图结果重组去重的方式,默认是nms;设置--match_threshold表示子图结果重组去重的阈值,默认是0.6;设置--match_metric表示子图结果重组去重的度量标准,默认是ios表示交小比(两个框交集面积除以更小框的面积),也可以选择交并比iou(两个框交集面积除以并集面积),精度效果因数据集而而异,但选择ios预测速度会更快一点。

在本项目中,我们把交小比和交并比两种方式都试验一番:

# 训练30个epoch后,子图拼图评估,交小比 !python tools/eval.py -c configs/smalldet/ppyoloe_crn_l_80e_sliced_visdrone_640_025_slice_infer.yml -o weights=output/ppyoloe_crn_l_80e_sliced_visdrone_640_025/best_model.pdparams --slice_infer --combine_method=nms --match_threshold=0.6 --match_metric=ios /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/vision/transforms/functional_pil.py:36: DeprecationWarning: NEAREST is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.NEAREST or Dither.NONE instead. 'nearest': Image.NEAREST, /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/vision/transforms/functional_pil.py:37: DeprecationWarning: BILINEAR is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.BILINEAR instead. 'bilinear': Image.BILINEAR, /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/vision/transforms/functional_pil.py:38: DeprecationWarning: BICUBIC is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.BICUBIC instead. 'bicubic': Image.BICUBIC, /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/vision/transforms/functional_pil.py:39: DeprecationWarning: BOX is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.BOX instead. 'box': Image.BOX, /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/vision/transforms/functional_pil.py:40: DeprecationWarning: LANCZOS is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.LANCZOS instead. 'lanczos': Image.LANCZOS, /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/vision/transforms/functional_pil.py:41: DeprecationWarning: HAMMING is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.HAMMING instead. 'hamming': Image.HAMMING Warning: Unable to use OC-SORT, please install filterpy, for example: `pip install filterpy`, see https://github.com/rlabbe/filterpy Warning: import ppdet from source directory without installing, run 'python setup.py install' to install ppdet firstly W0906 00:58:13.224578 584 device_context.cc:447] Please NOTE: device: 0, GPU Compute Capability: 7.0, Driver API Version: 11.2, Runtime API Version: 10.1 W0906 00:58:13.229662 584 device_context.cc:465] device: 0, cuDNN Version: 7.6. loading annotations into memory... Done (t=0.02s) creating index... index created! [09/06 00:58:23] ppdet.data.source.coco INFO: 1932 samples and slice to 1932 sub_samples in file /home/aistudio/MyDataset/IMG_sliced/val_640_025.json [09/06 00:58:24] ppdet.utils.checkpoint INFO: Finish loading model weights: output/ppyoloe_crn_l_80e_sliced_visdrone_640_025/best_model.pdparams [09/06 00:58:25] ppdet.engine INFO: Eval iter: 0 [09/06 00:58:35] ppdet.engine INFO: Eval iter: 100 [09/06 00:58:45] ppdet.engine INFO: Eval iter: 200 [09/06 00:58:57] ppdet.engine INFO: Eval iter: 300 [09/06 00:59:07] ppdet.engine INFO: Eval iter: 400 [09/06 00:59:19] ppdet.engine INFO: Eval iter: 500 [09/06 00:59:31] ppdet.engine INFO: Eval iter: 600 [09/06 00:59:42] ppdet.engine INFO: Eval iter: 700 [09/06 00:59:52] ppdet.engine INFO: Eval iter: 800 [09/06 01:00:02] ppdet.engine INFO: Eval iter: 900 [09/06 01:00:13] ppdet.engine INFO: Eval iter: 1000 [09/06 01:00:24] ppdet.engine INFO: Eval iter: 1100 [09/06 01:00:36] ppdet.engine INFO: Eval iter: 1200 [09/06 01:00:46] ppdet.engine INFO: Eval iter: 1300 [09/06 01:00:58] ppdet.engine INFO: Eval iter: 1400 [09/06 01:01:09] ppdet.engine INFO: Eval iter: 1500 [09/06 01:01:19] ppdet.engine INFO: Eval iter: 1600 [09/06 01:01:30] ppdet.engine INFO: Eval iter: 1700 [09/06 01:01:41] ppdet.engine INFO: Eval iter: 1800 [09/06 01:01:52] ppdet.engine INFO: Eval iter: 1900 [09/06 01:01:59] ppdetrics.metrics INFO: The bbox result is saved to bbox.json. loading annotations into memory... Done (t=0.02s) creating index... index created! [09/06 01:01:59] ppdetrics.coco_utils INFO: Start evaluate... Loading and preparing results... DONE (t=2.22s) creating index... index created! Running per image evaluation... Evaluate annotation type *bbox* DONE (t=9.34s). Accumulating evaluation results... DONE (t=2.21s). Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.419 Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=100 ] = 0.711 Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=100 ] = 0.444 Average Precision (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.399 Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.458 Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.474 Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 1 ] = 0.130 Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 10 ] = 0.442 Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.517 Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.452 Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.535 Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.701 [09/06 01:02:13] ppdet.engine INFO: Total sample number: 1932, averge FPS: 9.132096605227849 # 训练30个epoch后,子图拼图评估,交并比 !python tools/eval.py -c configs/smalldet/ppyoloe_crn_l_80e_sliced_visdrone_640_025_slice_infer.yml -o weights=output/ppyoloe_crn_l_80e_sliced_visdrone_640_025/best_model.pdparams --slice_infer --combine_method=nms --match_threshold=0.6 --match_metric=iou /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/vision/transforms/functional_pil.py:36: DeprecationWarning: NEAREST is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.NEAREST or Dither.NONE instead. 'nearest': Image.NEAREST, /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/vision/transforms/functional_pil.py:37: DeprecationWarning: BILINEAR is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.BILINEAR instead. 'bilinear': Image.BILINEAR, /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/vision/transforms/functional_pil.py:38: DeprecationWarning: BICUBIC is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.BICUBIC instead. 'bicubic': Image.BICUBIC, /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/vision/transforms/functional_pil.py:39: DeprecationWarning: BOX is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.BOX instead. 'box': Image.BOX, /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/vision/transforms/functional_pil.py:40: DeprecationWarning: LANCZOS is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.LANCZOS instead. 'lanczos': Image.LANCZOS, /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/vision/transforms/functional_pil.py:41: DeprecationWarning: HAMMING is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.HAMMING instead. 'hamming': Image.HAMMING Warning: Unable to use OC-SORT, please install filterpy, for example: `pip install filterpy`, see https://github.com/rlabbe/filterpy Warning: import ppdet from source directory without installing, run 'python setup.py install' to install ppdet firstly W0906 01:02:17.801489 1241 device_context.cc:447] Please NOTE: device: 0, GPU Compute Capability: 7.0, Driver API Version: 11.2, Runtime API Version: 10.1 W0906 01:02:17.806488 1241 device_context.cc:465] device: 0, cuDNN Version: 7.6. loading annotations into memory... Done (t=0.02s) creating index... index created! [09/06 01:02:27] ppdet.data.source.coco INFO: 1932 samples and slice to 1932 sub_samples in file /home/aistudio/MyDataset/IMG_sliced/val_640_025.json [09/06 01:02:29] ppdet.utils.checkpoint INFO: Finish loading model weights: output/ppyoloe_crn_l_80e_sliced_visdrone_640_025/best_model.pdparams [09/06 01:02:30] ppdet.engine INFO: Eval iter: 0 [09/06 01:03:10] ppdet.engine INFO: Eval iter: 100 [09/06 01:04:02] ppdet.engine INFO: Eval iter: 200 [09/06 01:04:47] ppdet.engine INFO: Eval iter: 300 [09/06 01:05:27] ppdet.engine INFO: Eval iter: 400 [09/06 01:06:14] ppdet.engine INFO: Eval iter: 500 [09/06 01:07:05] ppdet.engine INFO: Eval iter: 600 [09/06 01:07:55] ppdet.engine INFO: Eval iter: 700 [09/06 01:08:28] ppdet.engine INFO: Eval iter: 800 [09/06 01:09:18] ppdet.engine INFO: Eval iter: 900 [09/06 01:10:03] ppdet.engine INFO: Eval iter: 1000 [09/06 01:10:50] ppdet.engine INFO: Eval iter: 1100 [09/06 01:11:35] ppdet.engine INFO: Eval iter: 1200 [09/06 01:12:14] ppdet.engine INFO: Eval iter: 1300 [09/06 01:13:01] ppdet.engine INFO: Eval iter: 1400 [09/06 01:13:45] ppdet.engine INFO: Eval iter: 1500 [09/06 01:14:24] ppdet.engine INFO: Eval iter: 1600 [09/06 01:15:08] ppdet.engine INFO: Eval iter: 1700 [09/06 01:15:49] ppdet.engine INFO: Eval iter: 1800 [09/06 01:16:31] ppdet.engine INFO: Eval iter: 1900 [09/06 01:16:57] ppdetrics.metrics INFO: The bbox result is saved to bbox.json. loading annotations into memory... Done (t=0.02s) creating index... index created! [09/06 01:16:58] ppdetrics.coco_utils INFO: Start evaluate... Loading and preparing results... DONE (t=7.08s) creating index... index created! Running per image evaluation... Evaluate annotation type *bbox* DONE (t=16.24s). Accumulating evaluation results... DONE (t=4.36s). Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.471 Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=100 ] = 0.785 Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=100 ] = 0.502 Average Precision (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.443 Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.532 Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.567 Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 1 ] = 0.130 Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 10 ] = 0.480 Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.635 Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.530 Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.684 Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.870 [09/06 01:17:27] ppdet.engine INFO: Total sample number: 1932, averge FPS: 2.256297048751735 3.4 评估结论

将30个epoch后,原图训练、切图训练子图评估、切图训练原图评估、切图训练子图拼图评估的效果进行了对比,结果如下:

训练评估方式SLICE_SIZEOVERLAP_RATIOmAPval0.5:0.95APval0.5原图训练--33.864.0子图训练子图评估6400.2549.081.6子图训练原图评估6400.2538.973.3子图训练拼图评估 - IoS6400.2541.978.5子图训练拼图评估 - IoU6400.2547.171.1

从上面的简单表格可以明显看出,相比原图直接训练,子图训练拼图评估精度提升明显。同时,子图结果重组去重的度量标准用交并比在该数据集上表现更好,猜测可能是因为,数据集的目标大小差异较大,对于中大型目标,去重标准如果用交小比,在评估效果上,会比较吃亏。

4 拼图预测 # 准备一个放测试集图片的目录,然后将待预测的示例图片移至该目录下 !unzip -O GBK ../data/data163113/齿轮检测A榜评测数据.zip -d ../data/ !mkdir ../data/test !mv ../data/齿轮检测A榜评测数据/val/*.jpg ../data/test/ 4.1 单图切图拼图预测 # 挑一张测试集的图片展示预测效果 !python tools/infer.py -c configs/smalldet/ppyoloe_crn_l_80e_sliced_visdrone_640_025.yml -o weights=output/ppyoloe_crn_l_80e_sliced_visdrone_640_025/best_model.pdparams --infer_img=../data/test/1__H2_817171_IO-NIO198M_210121A0050-1-1.jpg --draw_threshold=0.25 --slice_infer --slice_size 640 640 --overlap_ratio 0.25 0.25 --combine_method=nms --match_threshold=0.6 --match_metric=iou --save_results=True /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/vision/transforms/functional_pil.py:36: DeprecationWarning: NEAREST is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.NEAREST or Dither.NONE instead. 'nearest': Image.NEAREST, /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/vision/transforms/functional_pil.py:37: DeprecationWarning: BILINEAR is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.BILINEAR instead. 'bilinear': Image.BILINEAR, /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/vision/transforms/functional_pil.py:38: DeprecationWarning: BICUBIC is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.BICUBIC instead. 'bicubic': Image.BICUBIC, /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/vision/transforms/functional_pil.py:39: DeprecationWarning: BOX is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.BOX instead. 'box': Image.BOX, /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/vision/transforms/functional_pil.py:40: DeprecationWarning: LANCZOS is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.LANCZOS instead. 'lanczos': Image.LANCZOS, /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/vision/transforms/functional_pil.py:41: DeprecationWarning: HAMMING is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.HAMMING instead. 'hamming': Image.HAMMING Warning: Unable to use OC-SORT, please install filterpy, for example: `pip install filterpy`, see https://github.com/rlabbe/filterpy Warning: import ppdet from source directory without installing, run 'python setup.py install' to install ppdet firstly W0906 14:35:08.361063 26272 device_context.cc:447] Please NOTE: device: 0, GPU Compute Capability: 7.0, Driver API Version: 11.2, Runtime API Version: 10.1 W0906 14:35:08.364892 26272 device_context.cc:465] device: 0, cuDNN Version: 7.6. [09/06 14:35:12] ppdet.utils.checkpoint INFO: Finish loading model weights: output/ppyoloe_crn_l_80e_sliced_visdrone_640_025/best_model.pdparams 1 samples and slice to 12 sub_samples loading annotations into memory... Done (t=0.01s) creating index... index created! 100%|███████████████████████████████████████████| 12/12 [00:35


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3