**Person:**person
Animal: bird, cat, cow, dog, horse, sheep
**Vehicle:**aeroplane, bicycle, boat, bus, car, motorbike, train
Indoor: bottle, chair, dining table, potted plant, sofa, tv/monitor
下载地址:The PASCAL Visual Object Classes Challenge 2012 (VOC2012) (ox.ac.uk)。
数据集的结构:
VOCdevkit
└── VOC2012
├── Annotations 所有的图像标注信息(XML文件)
├── ImageSets
│ ├── Action 人的行为动作图像信息
│ ├── Layout 人的各个部位图像信息
│ │
│ ├── Main 目标检测分类图像信息
│ │ ├── train.txt 训练集(5717)
│ │ ├── val.txt 验证集(5823)
│ │ └── trainval.txt 训练集+验证集(11540)
│ │
│ └── Segmentation 目标分割图像信息
│ ├── train.txt 训练集(1464)
│ ├── val.txt 验证集(1449)
│ └── trainval.txt 训练集+验证集(2913)
│
├── JPEGImages 所有图像文件
├── SegmentationClass 语义分割png图(基于类别)
└── SegmentationObject 实例分割png图(基于目标)
数据集包含物体检测和语义分割,我们只需要语义分割的数据集,所以可以考虑把多余的图片删除,删除的思路:
1、获取所有图片的name。
2、获取所有语义分割mask的name。
3、求二者的差集,然后将差集的name删除。
代码如下:
import glob
import os
image_all = glob.glob(‘data/VOCdevkit/VOC2012/JPEGImages/*.jpg’)
image_all_name = [image_file.replace(‘\’, ‘/’).split(‘/’)[-1].split(‘.’)[0] for image_file in image_all]
image_SegmentationClass = glob.glob(‘data/VOCdevkit/VOC2012/SegmentationClass/*.png’)
image_se_name= [image_file.replace(‘\’, ‘/’).split(‘/’)[-1].split(‘.’)[0] for image_file in image_SegmentationClass]
image_other=list(set(image_all_name) - set(image_se_name))
print(image_other)
for image_name in image_other:
os.remove(‘data/VOCdevkit/VOC2012/JPEGImages/{}.jpg’.format(image_name))
===============================================================
其他的代码也有很多,这篇比较好理解!
其实还有个比较好的图像分割库:https://github.com/qubvel/segmentation_models.pytorch
这个图像分割集合由俄罗斯的程序员小哥Pavel Yakubovskiy一手打造。在后面的文章,我也会使用这个库演示。
===============================================================
├── src: 模型的backbone以及FCN的搭建
├── train_utils: 训练、验证以及多GPU训练相关模块
├── my_dataset.py: 自定义dataset用于读取VOC数据集
├── train.py: 以fcn_resnet50(这里使用了Dilated/Atrous Convolution)进行训练
├── predict.py: 简易的预测脚本&#x