https://mp.weixin.qq.com/s?__biz=MzU1NzgzNTI3NA==&mid=2247483758&idx=1&sn=9ffbf44afedeb9d0a54d174282c1301a&chksm=fc2ef40bcb597d1d8da995615fd84b3ad8653cac7e68744e9eae2
原创 茶心 机器学习 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