COCO数据格式
COCO数据格式是许多框架与网络结构通用的数据格式,这里给出一般标注的图片数据格式转换为COCO的数据格式,存储为json文件。
存储主干部分
dataset = { 'info': {
'description': "This is stable 1.0 version of the 2014 MS COCO dataset.",
'url': "http://mscoco.org",
'version': "1.0",
'year': 2018,
'contributor': "Group",
'date_created': "2018-10-19 22:00:00.357475"},
'images':[],
'annotations':[],
'categories': [
{'supercategory:': 'car', 'id': 1, 'name': 'car'}]
}
代码如下
可根据自己的数据格式,调整读取标注文件的过程,注意与图片名称的对应关系
import sys
import json
import cv2
import os
import shutil
dataset = {
'info': {
'description': "This is stable 1.0 version of the 2014 MS COCO dataset.",
'url': "http://mscoco.org",
'version': "1.0",
'year': 2018,
'contributor': "Group",
'date_created': "2018-10-19 22:00:00.357475"},
'images':[],
'annotations':[],
'categories': [
{
'supercategory:': 'car', 'id': 1, 'name': 'car'},
{
'supercategory:': 'car', 'id': 2, 'name': 'van'},
{
'supercategory:': 'bus', 'id': 3, 'name': 'bus'},
{
'supercategory:': 'truck', 'id': 4, 'name': 'truck'},
{
'supercategory:': 'truck', 'id': 5, 'name': 'forklift'},
{
'supercategory:': 'person', 'id': 6, 'name': 'person'},
{
'supercategory:': 'person', 'id': 7, 'name': 'person-sitting'},
{
'supercategory:': 'bicycle', 'id': 8,