1、标准的coco数据标注的格式与下载

Dataset - COCO Dataset 数据特点

COCO数据集标注格式详解----object instances

Dataset之COCO数据集:COCO数据集的简介、下载、使用方法之详细攻略

COCO/VOC 数据集加速下载

{
    "images": [
        {
            "height": 682,
            "width": 1024,
            "id": 1,
            "file_name": "terrain2.png"
        }
    ],
    "categories": [
        {
            "supercategory": "car",
            "id": 1,
            "name": "car"
        }
    ],
    "annotations": [
        {
            "iscrowd": 0,
            "image_id": 1,
            "bbox": [
                218.0,
                448.0,
                222.0,
                161.0
            ],
            "segmentation": [
                [
                    218.0,
                    448.0,
                    440.0,
                    448.0,
                    440.0,
                    609.0,
                    218.0,
                    609.0
                ]
            ],
            "category_id": 1,
            "id": 1,
            "area": 698368
        },
        {
            "iscrowd": 0,
            "image_id": 1,
            "bbox": [
                501.0,
                451.0,
                121.0,
                92.0
            ],
            "segmentation": [
                [
                    501.0,
                    451.0,
                    622.0,
                    451.0,
                    622.0,
                    543.0,
                    501.0,
                    543.0
                ]
            ],
            "category_id": 1,
            "id": 2,
            "area": 698368
        },
        {
            "iscrowd": 0,
            "image_id": 1,
            "bbox": [
                634.0,
                437.0,
                81.0,
                56.0
            ],
            "segmentation": [
                [
                    634.0,
                    437.0,
                    715.0,
                    437.0,
                    715.0,
                    493.0,
                    634.0,
                    493.0
                ]
            ],
            "category_id": 1,
            "id": 3,
            "area": 698368
        },
        {
            "iscrowd": 0,
            "image_id": 1,
            "bbox": [
                725.0,
                423.0,
                70.0,
                51.0
            ],
            "segmentation": [
                [
                    725.0,
                    423.0,
                    795.0,
                    423.0,
                    795.0,
                    474.0,
                    725.0,
                    474.0
                ]
            ],
            "category_id": 1,
            "id": 4,
            "area": 698368
        },
        {
            "iscrowd": 0,
            "image_id": 1,
            "bbox": [
                791.0,
                404.0,
                40.0,
                47.0
            ],
            "segmentation": [
                [
                    791.0,
                    404.0,
                    831.0,
                    404.0,
                    831.0,
                    451.0,
                    791.0,
                    451.0
                ]
            ],
            "category_id": 1,
            "id": 5,
            "area": 698368
        }
    ]
}

1.1、COCO数据基本结构

这3种类型共享下面所列的基本类型,包括info、image、license,而annotation类型则呈现出了多态,会根据不同的任务具有不同的数据标注形式。

{
"info" : info,
"images" : [image], 
"annotations" : [annotation],
"licenses" : [license],
}

info{
"year" : int,
"version" : str,
"description" : str,
"contributor" : str,
"url" : str,
"date_created" : datetime,
}

image{
"id" : int,
"width" : int,
"height" : int,
"file_name" : str,
"license" : int,
"flickr_url" : str,
"coco_url" : str,
"date_captured" : datetime,
}

license{
"id" : int,
"name" : str,
"url" : str,
}

除了Annotation数据之外的数据类型举例如下:

1)info类型,比如一个info类型的实例:

"info":{
    "description":"This is stable 1.0 version of the 2014 MS COCO dataset.",
    "url":"http:\/\/mscoco.org",
    "version":"1.0","year":2014,
    "contributor":"Microsoft COCO group",
    "date_created":"2015-01-27 09:11:52.357475"
}

2)Images类型,Images是包含多个image实例的数组,对于一个image类型的实例:

{
    "license":3,
    "file_name":"COCO_val2014_000000391895.jpg",
    "coco_url":"http:\/\/mscoco.org\/images\/391895",
    "height":360,"width":640,"date_captured":"2013-11-14 11:18:45",
    "flickr_url":"http:\/\/farm9.staticflickr.com\/8186\/8119368305_4e622c8349_z.jpg",
    "id":391895
}

3)licenses类型,licenses是包含多个license实例的数组,对于一个license类型的实例:

{
    "url":"http:\/\/creativecommons.org\/licenses\/by-nc-sa\/2.0\/",
    "id":1,
    "name":"Attribution-NonCommercial-ShareAlike License"

1.2、COCO数据基本结构(Object Instance 类型的标注格式)

1)整体JSON文件格式
Object Instance这种格式的文件从头至尾按照顺序分为以下段落:

{
    "info": info,
    "licenses": [license],
    "images": [image],
    "annotations": [annotation],
    "categories": [category]
}
是的,你打开这两个文件,虽然内容很多,但从文件开始到结尾按照顺序就是这5段。其中,info、licenses、images这三个结构体/类型 在上一节中已经说了,在不同的JSON文件中这三个类型是一样的,定义是共享的。不共享的是annotation和category这两种结构体,他们在不同类型的JSON文件中是不一样的。

PS,mages数组、annotations数组、categories数组的元素数量是相等的,等于图片的数量。

2)annotations字段
annotations字段是包含多个annotation实例的一个数组,annotation类型本身又包含了一系列的字段,如这个目标的category id和segmentation mask。segmentation格式取决于这个实例是一个单个的对象(即iscrowd=0,将使用polygons格式)还是一组对象(即iscrowd=1,将使用RLE格式)。如下所示:

annotation{
    "id": int,
    "image_id": int,
    "category_id": int,
    "segmentation": RLE or [polygon],
    "area": float,
    "bbox": [x,y,width,height],
    "iscrowd": 0 or 1,
}

注意,单个的对象(iscrowd=0)可能需要多个polygon来表示,比如这个对象在图像中被挡住了。而iscrowd=1时(将标注一组对象,比如一群人)的segmentation使用的就是RLE格式。

另外,每个对象(不管是iscrowd=0还是iscrowd=1)都会有一个矩形框bbox ,矩形框左上角的坐标和矩形框的长宽会以数组的形式提供,数组第一个元素就是左上角的横坐标值。

其中,area是框的面积(area of encoded masks)。

3)categories字段
annotation结构中的categories字段存储的是当前对象所属的category的id,以及所属的supercategory的name。
categories是一个包含多个category实例的数组,而category结构体描述如下:

{
    "id": int,
    "name": str,
    "supercategory": str,
}

从instances_val2017.json文件中摘出的2个category实例如下所示:

{
    "supercategory": "person",
    "id": 1,
    "name": "person"
},
{
    "supercategory": "vehicle",
    "id": 2,
    "name": "bicycle"
},
......

2、Create your own COCO-style datasets(构造自己格式的COCO数据)

Create your own COCO-style datasets,这个页面讲述了能够构造的COCO数据类型的详情信息,标注coco的Annotation工具,通过COCO的支持实现深度学习。

我们所要做的就是循环遍历每个图像jpeg及其对应的注释png,并让pycococreator生成正确格式的项。第90和91行创建图像条目,而第112-114行处理注释。
#!/usr/bin/env python3import datetime
import json
import os
import re
import fnmatch
from PIL import Image
import numpy as np
from pycococreatortools import pycococreatortoolsROOT_DIR = 'train'
IMAGE_DIR = os.path.join(ROOT_DIR, "shapes_train2018")
ANNOTATION_DIR = os.path.join(ROOT_DIR, "annotations")INFO = {"description": "Example Dataset","url": "https://github.com/waspinator/pycococreator","version": "0.1.0","year": 2018,"contributor": "waspinator","date_created": datetime.datetime.utcnow().isoformat(' ')
}LICENSES = [{"id": 1,"name": "Attribution-NonCommercial-ShareAlike License","url": "http://creativecommons.org/licenses/by-nc-sa/2.0/"}
]CATEGORIES = [{'id': 1,'name': 'square','supercategory': 'shape',},{'id': 2,'name': 'circle','supercategory': 'shape',},{'id': 3,'name': 'triangle','supercategory': 'shape',},
]def filter_for_jpeg(root, files):file_types = ['*.jpeg', '*.jpg']file_types = r'|'.join([fnmatch.translate(x) for x in file_types])files = [os.path.join(root, f) for f in files]files = [f for f in files if re.match(file_types, f)]return filesdef filter_for_annotations(root, files, image_filename):file_types = ['*.png']file_types = r'|'.join([fnmatch.translate(x) for x in file_types])basename_no_extension = os.path.splitext(os.path.basename(image_filename))[0]file_name_prefix = basename_no_extension + '.*'files = [os.path.join(root, f) for f in files]files = [f for f in files if re.match(file_types, f)]files = [f for f in files if re.match(file_name_prefix, os.path.splitext(os.path.basename(f))[0])]return filesdef main():coco_output = {"info": INFO,"licenses": LICENSES,"categories": CATEGORIES,"images": [],"annotations": []}image_id = 1segmentation_id = 1# filter for jpeg imagesfor root, _, files in os.walk(IMAGE_DIR):image_files = filter_for_jpeg(root, files)# go through each imagefor image_filename in image_files:image = Image.open(image_filename)image_info = pycococreatortools.create_image_info(image_id, os.path.basename(image_filename), image.size)coco_output["images"].append(image_info)# filter for associated png annotationsfor root, _, files in os.walk(ANNOTATION_DIR):annotation_files = filter_for_annotations(root, files, image_filename)# go through each associated annotationfor annotation_filename in annotation_files:print(annotation_filename)class_id = [x['id'] for x in CATEGORIES if x['name'] in annotation_filename][0]category_info = {'id': class_id, 'is_crowd': 'crowd' in image_filename}binary_mask = np.asarray(Image.open(annotation_filename).convert('1')).astype(np.uint8)annotation_info = pycococreatortools.create_annotation_info(segmentation_id, image_id, category_info, binary_mask,image.size, tolerance=2)if annotation_info is not None:coco_output["annotations"].append(annotation_info)segmentation_id = segmentation_id + 1image_id = image_id + 1with open('{}/instances_shape_train2018.json'.format(ROOT_DIR), 'w') as output_json_file:json.dump(coco_output, output_json_file)if __name__ == "__main__":main()

3、COCO数据处理工具箱(Pycocotools)

Github链接,visualizing it using the COCO API.

COCO数据评估的案例代码

%matplotlib inline
import matplotlib.pyplot as plt
from pycocotools.coco import COCO
from pycocotools.cocoeval import COCOeval
import numpy as np
import skimage.io as io
import pylab
pylab.rcParams['figure.figsize'] = (10.0, 8.0)
annType = ['segm','bbox','keypoints']
annType = annType[1]      #specify type here
prefix = 'person_keypoints' if annType=='keypoints' else 'instances'
print 'Running demo for *%s* results.'%(annType)
#initialize COCO ground truth api
dataDir='../'
dataType='val2014'
annFile = '%s/annotations/%s_%s.json'%(dataDir,prefix,dataType)
cocoGt=COCO(annFile)
#initialize COCO detections api
resFile='%s/results/%s_%s_fake%s100_results.json'
resFile = resFile%(dataDir, prefix, dataType, annType)
cocoDt=cocoGt.loadRes(resFile)imgIds=sorted(cocoGt.getImgIds())
imgIds=imgIds[0:100]
imgId = imgIds[np.random.randint(100)]# running evaluation
cocoEval = COCOeval(cocoGt,cocoDt,annType)
cocoEval.params.imgIds  = imgIds
cocoEval.evaluate()
cocoEval.accumulate()
cocoEval.summarize()

模型结果的评估、可视化

python3 -m venv .venv
. .venv/bin/activate
pip install -r requirements.txt
streamlit run coco_explorer.py -- --coco_train ./coco_data/ground_truth_annotations.json --coco_predictions ./coco_data/predictions.json  --images_path ./coco_data/val2017/

COCO数据集简介与处理相关推荐

  1. 【Detectron2】使用 Detectron2 训练基于 coco 数据集的目标检测网络

    文章目录 一.安装 Detectron2 二.软连接 coco 数据集 三.训练 四.数据集相关参数 五.输出结果路径 六.COCO 数据集简介 七.模型相关参数 八.可视化结果 一.安装 Detec ...

  2. Dataset之COCO数据集:COCO数据集的简介、下载、使用方法之详细攻略

    Dataset之COCO数据集:COCO数据集的简介.安装.使用方法之详细攻略 目录 COCO数据集的简介 0.COCO数据集的80个类别-YoloV3算法采用的数据集 1.COCO数据集的意义 2. ...

  3. 2020-12-18 Dataset之COCO数据集:COCO数据集的简介、下载

    Dataset之COCO数据集:COCO数据集的简介.下载 COCO数据集的简介 MS COCO的全称是Microsoft Common Objects in Context,起源于微软于2014年出 ...

  4. 如何正确使用COCO数据集

    点击上方"小白学视觉",选择加"星标"或"置顶" 重磅干货,第一时间送达 简介 COCO数据集,意为"Common Objects ...

  5. Microsoft COCO 数据集

    篇博客主要以介绍MS COCO数据集为目标,分为3个部分:COCO介绍,数据集分类和COCO展示. 本人主要下载了其2014年版本的数据,一共有20G左右的图片和500M左右的标签文件.标签文件标记了 ...

  6. COCO 数据集的使用

    Windows 10 编译 Pycocotools 踩坑记 COCO数据库简介 微软发布的COCO数据库, 除了图片以外还提供物体检测, 分割(segmentation)和对图像的语义文本描述信息. ...

  7. coco数据集大小分类_Microsoft COCO 数据集

    本篇博客主要以介绍MS COCO数据集为目标,分为3个部分:COCO介绍,数据集分类和COCO展示. 本人主要下载了其2014年版本的数据,一共有20G左右的图片和500M左右的标签文件.标签文件标记 ...

  8. coco数据集大小分类_COCO数据集使用

    一.简介 官方网站:http://cocodataset.org/ 全称:Microsoft Common Objects in Context (MS COCO) 支持任务:Detection.Ke ...

  9. coco数据集大小分类_2019-08-15 COCO数据集

    官网:cocodataset.org COCO has five annotation types: for object detection, keypoint detection, stuff s ...

最新文章

  1. 在Objective-C中创建一个抽象类
  2. TCP/IP协议分为哪四层,具体作用是什么。
  3. java对象复制到新对象_java – 使用新生成的ID将Hibernate复制对象值复制到新对象中...
  4. 思科asa5515端口映射_Cisco ASA端口映射
  5. vmware网络桥接模式无法上网的解决办法
  6. STM32工作笔记0047--认识DTU什么是4GDTU设备
  7. AJAX编写用户注册实例及技术小结
  8. 2021-09-02 网安实验-文件修复-CTF中的压缩包
  9. Unity渲染性能优化总纲
  10. 关于新版微信电脑版HOOK的技术经验(WX电脑版3.0)
  11. InputBox函数用法小结
  12. twitter、facebook、pinterest、linkedin 分享代码
  13. 华为实验-关于不同vlan之间的互通 混合实验
  14. unity沙子堆积_Unity Shader 之 简单实现沙漠干旱热浪的效果
  15. 习题4-5 换硬币 (20分) 将一笔零钱换成5分、2分和1分的硬币,要求每种硬币至少有一枚,有几种不同的换法?
  16. 京东智联云:2019年云综合收入9.0亿元,波澜不惊
  17. css 定位连线_前端css实现两点连线
  18. python自制个人网盘_超简单!基于Python搭建个人“云盘”
  19. 秦的成功得益于崇拜制度和规则
  20. Cocos2d开发系列(二)

热门文章

  1. ajax请求方式 问答题,java spring mvc面试题,九大常见问答题
  2. Ubuntu安装peda
  3. IBM X3850服务器数据恢复成功案例
  4. 学校计算机教室的用途,特殊教育学校功能室功能用途超级全.docx
  5. 什么是暂时性死区(TDZ)?
  6. 西门子200Smart加维纶触摸屏程序画面程序案例,项目内容为某制造企业疫苗车间控制系统,报告配液工艺
  7. vs2012运行项目报未能加载文件或程序集“System.Web.Mvc, Version=4.0.0.1,Culture=neutral”问题和解决方法...
  8. SIM卡套卡住的解决方法
  9. python算法交易工程师_清华编程高手尹成带你基于算法实践python量化交易
  10. echarts地图绘制