C O C O 数 据 集 制 作 COCO数据集制作 COCO数据集制作
【实战】Windows10+YOLOv3实现检测自己的数据集(1)——制作自己的数据集
首先确定输入模型的coco检测和分割的数据形式
labelme制作数据集转COCO数据格式
labelimg制作数据集转COCO数据格式
coco数据集可以用于做 目标检测
和语义分割
coco数据集的标签信息是以.json的格式存储的
一 介绍
MS COCO的全称是Microsoft Common Objects in Context,源于微软于2014年出资标注的Microsoft COCO数据集,其地位与ImageNet等同,是衡量通用模型性能的最佳数据集之一。
COCO数据集是一个大型的、丰富的物体检测,分割和字幕数据集。
以scene understanding为目标,主要从复杂的日常场景中截取,图像中的目标通过精确的segmentation进行位置的标定。
图像包括91类目标,328,000影像和2,500,000个label。
目前为止有语义分割的最大数据集,提供的类别有80 类,有超过33 万张图片,其中20 万张有标注,整个数据集中个体的数目超过150 万个
下载
1、2014年数据集的下载
http://msvocds.blob.core.windows.net/coco2014/train2014.zip
2、2017的数据集的下载
http://images.cocodataset.org/zips/train2017.zip
http://images.cocodataset.org/annotations/annotations_trainval2017.zip
http://images.cocodataset.org/zips/val2017.zip
http://images.cocodataset.org/annotations/stuff_annotations_trainval2017.zip
http://images.cocodataset.org/zips/test2017.zip
http://images.cocodataset.org/annotations/image_info_test2017.zip
实现案例
import json
import os
import cv2
import shutil
import xml.etree.ElementTree as ET
dataset = {
}
def readxml(dataset,xml,count):
tree = ET.parse(xml)
root = tree.getroot()
for child in root:
if child.tag == "size":
for s_ch in child:
if s_ch.tag == "width":
w = s_ch.text
else :
h = s_ch.text
elif child.tag == "object":
for s_ch in child:
if s_ch.tag == "bndbox":
for ss_ch in s_ch:
if ss_ch.tag == "xmin":
xmin = ss_ch.text
elif ss_ch.tag == "ymin":
ymin = ss_ch.text
elif ss_ch.tag == "xmax":
xmax = ss_ch.text
elif ss_ch.tag == "ymax":
ymax = ss_ch.text
else:
ca_name = s_ch.text
dataset.setdefault("images",[]).append({
'file_name': str(count) +'.jpg',
'id': int(count),
'width': int(w),
'height': int(h)
})
dataset.setdefault("annotations",[]).append({
'image_id': int(count),
'bbox': [int(xmin), int(ymin), int(xmax)-int(xmin), int(ymax)-int(ymin)],
'category_id': 6,
'area':int(w) * int(h),
'iscrowd':0,
'id':int(count),
'segmentation':[]
})
im_path="/home/qusongyun/images/"
trainimg = "/home/qusongyun/simpledet/data/coco/images/val2014/"
cmax = 0
dirpath = os.listdir(im_path)
for imgdir in dirpath:
f1 = os.listdir(trainimg)
for file in f1:
cmax = max(cmax,int(file.split(".")[0]))
count = 1
for file in os.listdir(im_path + imgdir):
if file.split(".")[1] == "jpg":
oldname = os.path.join(im_path + imgdir, file)
jpgname = os.path.join(trainimg, str(count+cmax) + ".jpg")
shutil.copyfile(oldname, jpgname)
readxml(dataset,os.path.join(im_path + imgdir , file.split(".")[0] + ".xml"),count+cmax)
count += 1
for i in range(1,81):
dataset.setdefault("categories",[]).append({
'id': i,
'name':1,
'supercategory': 'No'
})
folder = os.path.join('/home/qusongyun/simpledet/data/coco/annotations/')
if not os.path.exists(folder):
os.makedirs(folder)
json_name = os.path.join(folder+'instances_minival2014.json')
with open(json_name, 'w') as f:
json.dump(dataset, f)
参考文献
https://patrickwasp.com/create-your-own-coco-style-dataset/