全系列
[win 10] maskrcnn-benchmark 上手(1)——配置环境与coco数据集介绍
[win 10] maskrcnn-benchmark 上手(2)——开始训练
[win 10] maskrcnn-benchmark 上手(3)—— faster-rcnn 推理
博主win10
)目录
- 0. 配置环境
- 1. Coco数据集介绍
- 1.1 info
- 1.2 images
- 1.3 licenses
- 1.4 annotations
- 1.5 categories
- Reference
按照官网配置,遇到问题参考我之前的博客。这次我是在win10上完成全部的配置,demo都可以顺利运行。主要的pytorch 版本虽然官网说一定要1.0.0,但是1.1.0实测后其实也可以。torchvision==0.3.0,不能是0.4.0,不然报错,issue中有描述。
conda install pytorch==1.1.0 torchvision==0.3.0 cudatoolkit=10.0 -c pytorch
略过demo运行那,由于我是第一次使用coco,去coco官网需要自己下载数据集。这就遇到一个很烦的问题,不知道下载哪一个,找不到instance的数据集,只有stuff。
多亏了知乎文章,对coco api有了一定了解。因为这是个公共大的数据集,所以有公共的api和规范,dataloader和平常的就不一样。COCO的 全称是Common Objects in COntext,是微软团队提供的一个可以用来进行图像识别的数据集。MS COCO数据集中的图像分为训练、验证和测试集。COCO通过在Flickr上搜索80个对象类别和各种场景类型来收集图像,其使用了亚马逊的Mechanical Turk(AMT)。
object instances(目标实例)、object keypoints(目标上的关键点)、image captions(看图说话)这3种类型共享这些基本类型:info、image、license。
在instance segmentation 中,包含这么5种key。
{
"info": info,
"licenses": [license],
"images": [image],
"annotations": [annotation],
"categories": [category]
}
共有的三种key结构
info{
"year": int,
"version": str,
"description": str,
"contributor": str,
"url": str,
"date_created": datetime,
}
license{
"id": int,
"name": str,
"url": str,
}
image{
"id": int,
"width": int,
"height": int,
"file_name": str,
"license": int,
"flickr_url": str,
"coco_url": str,
"date_captured": datetime,
}
由于打开那个json太卡了。。。仅仅详细展开了很少部分。
"info":
{"description": "COCO 2017 Dataset",
"url": "http://cocodataset.org",
"version": "1.0",
"year": 2017,
"contributor": "COCO Consortium",
"date_created": "2017/09/01"},
images 是一个数组,其中包含了很多image的实例,image的结构参照共有部分结构。
"images":
[{"license": 4,
"file_name": "000000397133.jpg",
"coco_url": "http://images.cocodataset.org/val2017/000000397133.jpg",
"height": 427,
"width": 640,
"date_captured": "2013-11-14 17:02:52",
"flickr_url": "http://farm7.staticflickr.com/6116/6255196340_da26cf2c9e_z.jpg",
"id": 397133},
{"license": 1,
"file_name": "000000037777.jpg",
"coco_url": "http://images.cocodataset.org/val2017/000000037777.jpg",
"height": 230,
"width": 352,
"date_captured": "2013-11-14 20:55:31",
"flickr_url": "http://farm9.staticflickr.com/8429/7839199426_f6d48aa585_z.jpg",
"id": 37777},
{"license": 4,
"file_name": "000000252219.jpg",
"coco_url": "http://images.cocodataset.org/val2017/000000252219.jpg",
"height": 428,
"width": 640,
...
licenses也是个数组,同images。
"licenses":
[{"url": "http://creativecommons.org/licenses/by-nc-sa/2.0/",
"id": 1,
"name": "Attribution-NonCommercial-ShareAlike License"},
{"url": "http://creativecommons.org/licenses/by-nc/2.0/",
"id": 2,
"name": "Attribution-NonCommercial License"},
{"url": "http://creativecommons.org/licenses/by-nc-nd/2.0/",
"id": 3,
"name": "Attribution-NonCommercial-NoDerivs License"},
{"url": "http://creativecommons.org/licenses/by/2.0/",
"id": 4,
"name": "Attribution License"},
{"url": "http://creativecommons.org/licenses/by-sa/2.0/",
"id": 5,
"name": "Attribution-ShareAlike License"},
{"url": "http://creativecommons.org/licenses/by-nd/2.0/",
"id": 6,"name": "Attribution-NoDerivs License"},
...
基本的annotation如下,“segmentation”: RLE or [polygon]需要解释下。segmentation格式取决于这个实例是一个单个的对象(即iscrowd=0,将使用polygons格式)还是一组对象(即iscrowd=1,将使用RLE格式)
。当三个人重叠时候,iscrowd=1,而旁边一个单独的人就是0。
annotation{
"id": int,
"image_id": int,
"category_id": int,
"segmentation": RLE or [polygon],
"area": float,
"bbox": [x,y,width,height],
"iscrowd": 0 or 1,
}
polygons中文多边形,而RLE是游程编码(run-length encoding)?官网对RLE的注释如下,那么大概翻译一下例子。given M=[0 0 1 1 1 0 1] the RLE counts would be [2 3 1 1], or for M=[1 1 1 1 1 1 0] the counts would be [0 6 1] (note that the odd counts are always the numbers of zeros). 大家注意,M开头是1,则编码后第一个是0,就这么简单,编码牛逼!
# RLE is a simple yet efficient format for storing binary masks. RLE
# first divides a vector (or vectorized image) into a series of piecewise
# constant regions and then for each piece simply stores the length of
# that piece. For example, given M=[0 0 1 1 1 0 1] the RLE counts would
# be [2 3 1 1], or for M=[1 1 1 1 1 1 0] the counts would be [0 6 1]
# (note that the odd counts are always the numbers of zeros). Instead of
# storing the counts directly, additional compression is achieved with a
# variable bitrate representation based on a common scheme called LEB128.
具体地:
ploygon:这是对于单个对象来说的,表示的是多边形轮廓的写x,y坐标,肯定是偶数,如果有n个数,表示有n/2个坐标
RLE:为了表示像素标注,可以用0,1表示,1表示有对象,然后利用RLE编码。
area是area of encoded masks,是标注区域的面积。如果是矩形框,那就是高乘宽,polygon或者RLE另算。
上一章节知识点很多,消化了不少。categories就是cls的字段了。
{
"id": int,
"name": str,
"supercategory": str,
}
举例:
{
"supercategory": "person",
"id": 1,
"name": "person"
},
{
"supercategory": "vehicle",
"id": 2,
"name": "bicycle"
},