基于深度学习的计算机视觉,可能都不可避免要训练自己的数据集。
1. 什么是数据集
以coco为例
特点是数据集庞大,有80类,识别很精准
yolo官方推荐的就是coco的(yolo.cfg, yolo.wrights)
40.jpg 63.jpg
可以看到,coco可以检测到别的没有的物体;
以上图片截取自网站hdvidzpro中的视频:(Hdvidz.in)_8K-4x-YOLO-Tiny-YOLO-VOC-COCO-YOLO9000-Object-Detection-1.mp4。
coco的官网中,我们看到图片都是有做segment, 比如
为什么要分割区域呢?
某些情况下,我们需要对图像的每个像素进行分类,也被称作是图像的分割。想象一下,假如有一个巨大的图片数据集,需要给人脸打上马赛克,这样我们就不必得到所有人的许可之后才能发布这些照片。例如,谷歌街景都对行人的脸做了模糊化处理。当然,我们只需要对图片中的人脸进行模糊处理,而不是所有的内容。图片分割可以帮助我们实现类似的需求。我们可以分割得到属于人脸的那部分像素,并只对它们进行模糊处理。
这个segment的坐标大致是这样的,有很多点,连成一个轮廓
segment.png2. 关于标注和标注工具
数据集的标注,包含了检测(detect),分割(segment), detect里面主要数据是bbox的坐标和class, 如果要用到segment属性
000793.jpgxml文件
<annotation>
<folder>VOC2012</folder>
<filename>2007_000793.jpg</filename>
<source>
<database>The VOC2007 Database</database>
<annotation>PASCAL VOC2007</annotation>
<image>flickr</image>
</source>
<size>
<width>500</width>
<height>375</height>
<depth>3</depth>
</size>
<segmented>1</segmented>
<object>
<name>person</name>
<pose>Rear</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>289</xmin>
<ymin>100</ymin>
<xmax>316</xmax>
<ymax>183</ymax>
</bndbox>
</object>
<object>
<name>person</name>
<pose>Rear</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>241</xmin>
<ymin>111</ymin>
<xmax>270</xmax>
<ymax>180</ymax>
</bndbox>
</object>
<object>
<name>person</name>
<pose>Rear</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>218</xmin>
<ymin>107</ymin>
<xmax>236</xmax>
<ymax>178</ymax>
</bndbox>
</object>
<object>
<name>person</name>
<pose>Rear</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>402</xmin>
<ymin>67</ymin>
<xmax>467</xmax>
<ymax>259</ymax>
</bndbox>
</object>
<object>
<name>person</name>
<pose>Frontal</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>65</xmin>
<ymin>110</ymin>
<xmax>84</xmax>
<ymax>161</ymax>
</bndbox>
</object>
<object>
<name>person</name>
<pose>Frontal</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>96</xmin>
<ymin>107</ymin>
<xmax>114</xmax>
<ymax>159</ymax>
</bndbox>
</object>
<object>
<name>person</name>
<pose>Unspecified</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>100</xmin>
<ymin>78</ymin>
<xmax>190</xmax>
<ymax>282</ymax>
</bndbox>
</object>
<object>
<name>person</name>
<pose>Unspecified</pose>
<truncated>0</truncated>
<difficult>1</difficult>
<bndbox>
<xmin>273</xmin>
<ymin>103</ymin>
<xmax>295</xmax>
<ymax>182</ymax>
</bndbox>
</object>
<object>
<name>bicycle</name>
<pose>Left</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>151</xmin>
<ymin>160</ymin>
<xmax>310</xmax>
<ymax>280</ymax>
</bndbox>
</object>
<object>
<name>bus</name>
<pose>Frontal</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>2</xmin>
<ymin>80</ymin>
<xmax>51</xmax>
<ymax>135</ymax>
</bndbox>
</object>
</annotation>
我们看到,即使标注了<segmented>1</segmented>,但是并没有对应的轮廓坐标,而且在voc_label.py和其它代码里,并没有对segmented对应的处理。
import xml.etree.ElementTree as ET
import pickle
import os
from os import listdir, getcwd
from os.path import join
sets=[('2012', 'train'), ('2012', 'val'), ('2007', 'train'), ('2007', 'val'), ('2007', 'test')]
classes = ["aeroplane", "bicycle", "bird", "boat", "bottle", "bus", "car", "cat", "chair", "cow", "diningtable", "dog", "horse", "motorbike", "person", "pottedplant", "sheep", "sofa", "train", "tvmonitor"]
def convert(size, box):
dw = 1./size[0]
dh = 1./size[1]
x = (box[0] + box[1])/2.0
y = (box[2] + box[3])/2.0
w = box[1] - box[0]
h = box[3] - box[2]
x = x*dw
w = w*dw
y = y*dh
h = h*dh
return (x,y,w,h)
def convert_annotation(year, image_id):
in_file = open('VOCdevkit/VOC%s/Annotations/%s.xml'%(year, image_id))
out_file = open('VOCdevkit/VOC%s/labels/%s.txt'%(year, image_id), 'w')
tree=ET.parse(in_file)
root = tree.getroot()
size = root.find('size')
w = int(size.find('width').text)
h = int(size.find('height').text)
for obj in root.iter('object'):
difficult = obj.find('difficult').text
cls = obj.find('name').text
if cls not in classes or int(difficult) == 1:
continue
cls_id = classes.index(cls)
xmlbox = obj.find('bndbox')
b = (float(xmlbox.find('xmin').text), float(xmlbox.find('xmax').text), float(xmlbox.find('ymin').text), float(xmlbox.find('ymax').text))
bb = convert((w,h), b)
out_file.write(str(cls_id) + " " + " ".join([str(a) for a in bb]) + '\n')
wd = getcwd()
for year, image_set in sets:
if not os.path.exists('VOCdevkit/VOC%s/labels/'%(year)):
os.makedirs('VOCdevkit/VOC%s/labels/'%(year))
image_ids = open('VOCdevkit/VOC%s/ImageSets/Main/%s.txt'%(year, image_set)).read().strip().split()
list_file = open('%s_%s.txt'%(year, image_set), 'w')
for image_id in image_ids:
list_file.write('%s/VOCdevkit/VOC%s/JPEGImages/%s.jpg\n'%(wd, year, image_id))
convert_annotation(year, image_id)
list_file.close()
网友评论