生成自己的coco数据集

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/

  • rail_1.json

  • rail_1.jpg

  • rail_2.json

  • rail_2.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
  • 8
    点赞
  • 30
    收藏
    觉得还不错? 一键收藏
  • 10
    评论
评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值