自制coco格式数据集

https://mp.weixin.qq.com/s?__biz=MzU1NzgzNTI3NA==&mid=2247483758&idx=1&sn=9ffbf44afedeb9d0a54d174282c1301a&chksm=fc2ef40bcb597d1d8da995615fd84b3ad8653cac7e68744e9eae2

生成自己的coco数据集

原创 茶心 机器学习 way forward 2019-06-14

1、环境准备

操作系统:macOS

python:3.6.0

 

2、coco数据集

文件夹格式:

coco/

  • annotations/

    • instances_train2017.json

    • instances_val2017.json

  • images/

    • rail_1.jpg

    • ...

    • rail_5.jpg

    • ...

    • train2017/

    • val2017

 

coco格式:

整体结构

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

info字段

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

licenses字段

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

images字段

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

annotations字段

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

annotations字段另外一种:segmentation中polygon格式

  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
{  "segmentation": [[510.66,423.01,511.72,420.03,510.45......]],  "area": 702.1057499999998,  "iscrowd": 0,  "image_id": 289343,  "bbox": [473.07,395.93,38.65,28.67],  "category_id": 18,  "id": 1768},

3、labelme文件夹

labelme/

  • 0d4c5e4f-fc3c-4d5a-906c-105.json

  • 0d4c5e4f-fc3c-4d5a-906c-105.jpg

  • 0ddfc5aea-fcdac-421-92dad-144.json

  • 0ddfc5aea-fcdac-421-92dad-144.jpg

 

4、原始数据集是一系列.jpg的图片

5、先将原始图片转为labelme

  •  
pip install labelme

安装好后运行labelme输入labelme即可

  •  
labelme

点击open dir选择数据集文件夹

然后右击选择create polygons标记多边形

点击save保存在图片同一路径下

6、labelme转coco数据格式(labelme2coco

下载labelme项目

  •  
git clone https://github.com/wkentaro/labelme.git

进入下图文件夹

将生成好的labelme文件放入data_annotated

删除data_dataset_coco文件夹

修改labels.txt文件中的类别

执行以下命令即可

  •  
./labelme2coco.py data_annotated data_dataset_coco --labels labels.txt

 

 

微信扫一扫
关注该公众号

238f9d2f7eebdd9d6761949&token=1011036895&lang=zh_CN#rd

  • 1
    点赞
  • 33
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值