COCO数据集是Microsoft制作收集用于Detection + Segmentation + Localization + Captioning的数据集。
根据年份来区分, 到目前为止, COCO 的数据集, 分别有 2014, 2015, 2017。
分大类12个,分别:
[‘appliance’, ‘food’, ‘indoor’, ‘accessory’, ‘electronic’, ‘furniture’, ‘vehicle’, ‘sports’, ‘animal’, ‘kitchen’, ‘person’, ‘outdoor’]
细分则共有小类80个,分别:
[‘person’, ‘bicycle’, ‘car’, ‘motorcycle’, ‘airplane’, ‘bus’, ‘train’, ‘truck’, ‘boat’, ‘traffic light’, ‘fire hydrant’, ‘stop sign’, ‘parking meter’, ‘bench’, ‘bird’, ‘cat’, ‘dog’, ‘horse’, ‘sheep’, ‘cow’, ‘elephant’, ‘bear’, ‘zebra’, ‘giraffe’, ‘backpack’, ‘umbrella’, ‘handbag’, ‘tie’, ‘suitcase’, ‘frisbee’, ‘skis’, ‘snowboard’, ‘sports ball’, ‘kite’, ‘baseball bat’, ‘baseball glove’, ‘skateboard’, ‘surfboard’, ‘tennis racket’, ‘bottle’, ‘wine glass’, ‘cup’, ‘fork’, ‘knife’, ‘spoon’, ‘bowl’, ‘banana’, ‘apple’, ‘sandwich’, ‘orange’, ‘broccoli’, ‘carrot’, ‘hot dog’, ‘pizza’, ‘donut’, ‘cake’, ‘chair’, ‘couch’, ‘potted plant’, ‘bed’, ‘dining table’, ‘toilet’, ‘tv’, ‘laptop’, ‘mouse’, ‘remote’, ‘keyboard’, ‘cell phone’, ‘microwave’, ‘oven’, ‘toaster’, ‘sink’, ‘refrigerator’, ‘book’, ‘clock’, ‘vase’, ‘scissors’, ‘teddy bear’, ‘hair drier’, ‘toothbrush’]
coco数据集直接到官网下载实在太慢,所以给大家推荐个实测下载速度达到几兆的(因实际环境会不同)
https://blog.csdn.net/ccbrid/article/details/79368639 在该博客的位置一个个点击就直接下载了。
下载解压后如图:
直接去下载win版的api https://github.com/philferriere/cocoapi
解压得 cocoapi-master文件夹如图:
然后cmd命令窗口,先把默认路径切换到该cocoapi-master文件夹里的PythonAPI对应路径( 如上图,则
cd C:\Users\87419\Desktop\cocoapi-master\PythonAPI ),输入python setup.py install
我第一次输入python setup.py install 时,报错 No module named Cython,则 pip install Cython 安装一下就好了 。
我这个比较顺利,直接就完事了(其实是之前用的其他方法,踩了好几个坑,最后才试到了这个正确的方法)。
注: 若要检查是否安装成功,可以到python的三方lib中(路径通常在lib\site-packages)看看有没有pycocotools文件夹,如下图
可以见到pycocotools中有一个coco.py文件,它是对coco数据json文件的解析工具(这也是我们前面要千辛万苦安装它的原因)
from pycocotools.coco import COCO
import numpy as np
import skimage.io as io
import matplotlib.pyplot as plt
import pylab
path = r'E:\Data_Summary\coco\annotations/instances_train2017.json'
coco = COCO(path)#1.读文件
def showImage(imgIds):
IDs = coco.getImgIds(imgIds)#2.获取ID
imgs = coco.loadImgs(IDs)[0]#3.根据ID读图,返回list
print(imgs)
imgFile = r'E:\Data_Summary\coco\images\train2017/'
imgURL = imgFile + imgs['file_name']
I = io.imread(imgURL)#4.读图
plt.imshow(I)
plt.show()
return imgs, I
'用类别来查询图片'
catIds = coco.getCatIds(catNms=['person'])
imgIds = coco.getImgIds(catIds=catIds)
print('imgIds:', imgIds[3])
imgs, I = showImage(imgIds[3])
plt.imshow(I)
annIds = coco.getAnnIds(imgs['id'])
imgAnns = coco.loadAnns(ids=annIds)
coco.showAnns(imgAnns)
plt.show()
详解见 https://blog.csdn.net/GodWriter/article/details/80049938