A Glance through COCO
Presented By R.G.
关于COCO
COCO的官网:https://cocodataset.org/
COCO API : https://github.com/cocodataset/cocoapi
以下是 COCO API 的 README
COCO is a large image dataset designed for object detection, segmentation, person keypoints detection, stuff segmentation, and caption generation. This package provides Matlab, Python, and Lua APIs that assists in loading, parsing, and visualizing the annotations in COCO. Please visit http://cocodataset.org/ for more information on COCO, including for the data, paper, and tutorials. The exact format of the annotations is also described on the COCO website. The Matlab and Python APIs are complete, the Lua API provides only basic functionality.
In addition to this API, please download both the COCO images and annotations in order to run the demos and use the API. Both are available on the project website.
-Please download, unzip, and place the images in: coco/images/
-Please download and place the annotations in: coco/annotations/
For substantially more details on the API please see http://cocodataset.org/#download.
After downloading the images and annotations, run the Matlab, Python, or Lua demos for example usage.
To install:
- For Matlab, add coco/MatlabApi to the Matlab path (OSX/Linux binaries provided)
- For Python, run “make” under coco/PythonAPI
- For Lua, run “luarocks make LuaAPI/rocks/coco-scm-1.rockspec” under coco/
关于COCO API的安装
参考我的另一篇文章:
【COCO数据集】python使用pip安装COCO API
COCO数据集配置
配置COCO数据集的路径
import sys,os
# 配置COCO数据集的路径
COCOPATH = os.path.join(os.getcwd(), 'COCO') # 这里配置你COCO数据集的所在路径,我是放在当前文件夹路径内
COCOPATH
'/Users/rgmax/Desktop/COCO_ABC/COCO'
查看路径(文件夹)下内容,可以看到由于是mac的缘故,多了一个’.DS_Store’
os.listdir(COCOPATH)
['image_info_test2017',
'.DS_Store',
'val2017',
'panoptic_annotations_trainval2017',
'test2017',
'stuff_annotations_trainval2017',
'unlabeled2017',
'annotations_trainval2017',
'train2017',
'image_info_unlabeled2017']
剔除mac自带的.DS_Store文件夹,并将COCO数据集所含的所有文件夹路径保存在COCODIRS字典中
COCODIRS = os.listdir(COCOPATH)
try: # 剔除mac自带的.DS_Store文件夹
COCODIRS.remove('.DS_Store')
except:
pass
# COCODIRS = [os.path.join(COCOPATH, d) for d in COCODIRS] # 生成完整文件夹路径
COCODIRS = {
# 改用字典比较好访问
d : os.path.join(COCOPATH, d) for d in COCODIRS
}
COCODIRS
{'image_info_test2017': '/Users/rgmax/Desktop/COCO_ABC/COCO/image_info_test2017',
'val2017': '/Users/rgmax/Desktop/COCO_ABC/COCO/val2017',
'panoptic_annotations_trainval2017': '/Users/rgmax/Desktop/COCO_ABC/COCO/panoptic_annotations_trainval2017',
'test2017': '/Users/rgmax/Desktop/COCO_ABC/COCO/test2017',
'stuff_annotations_trainval2017': '/Users/rgmax/Desktop/COCO_ABC/COCO/stuff_annotations_trainval2017',
'unlabeled2017': '/Users/rgmax/Desktop/COCO_ABC/COCO/unlabeled2017',
'annotations_trainval2017': '/Users/rgmax/Desktop/COCO_ABC/COCO/annotations_trainval2017',
'train2017': '/Users/rgmax/Desktop/COCO_ABC/COCO/train2017',
'image_info_unlabeled2017': '/Users/rgmax/Desktop/COCO_ABC/COCO/image_info_unlabeled2017'}
构建训练集对象train_set
# 构建训练集
train_set = [os.path.join(COCODIRS['train2017'],p) for p in os.listdir(COCODIRS['train2017'])]
train_set[:5] # 查看部分训练集(图片)
['/Users/rgmax/Desktop/COCO_ABC/COCO/train2017/000000109622.jpg',
'/Users/rgmax/Desktop/COCO_ABC/COCO/train2017/000000160694.jpg',
'/Users/rgmax/Desktop/COCO_ABC/COCO/train2017/000000308590.jpg',
'/Users/rgmax/Desktop/COCO_ABC/COCO/train2017/000000327573.jpg',
'/Users/rgmax/Desktop/COCO_ABC/COCO/train2017/000000062929.jpg']
构建验证集对象val_set
val_set = [os.path.join(COCODIRS['val2017'],p) for p in os.listdir(COCODIRS['val2017'])]
val_set[:5]
['/Users/rgmax/Desktop/COCO_ABC/COCO/val2017/000000182611.jpg',
'/Users/rgmax/Desktop/COCO_ABC/COCO/val2017/000000335177.jpg',
'/Users/rgmax/Desktop/C