我们使用coco数据集来训练我们的cornernet,首先下载数据集,存放路径为D:/dataset\coco\annotations\instances_train2017.json
我们主要是使用的.json文件。这里可以参考-----来了解.json文件的存储形式。
我们使用from pycocotools.coco import COCO这个工具来读取.json文件
1.首先我们要拿到所有的detection,也就是每张图片中有多少个detection,这些detection属于哪张图片,属于哪个类,这些detection的坐标是什么,
##cat_ids 对应关系表
_cat_ids = [
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13,
14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
24, 25, 27, 28, 31, 32, 33, 34, 35, 36,
37, 38, 39, 40, 41, 42, 43, 44, 46, 47,
48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
58, 59, 60, 61, 62, 63, 64, 65, 67, 70,
72, 73, 74, 75, 76, 77, 78, 79, 80, 81,
82, 84, 85, 86, 87, 88, 89, 90
]
_classes = {
ind + 1: cat_id for ind, cat_id in enumerate(_cat_ids)
}
_coco_to_class_map = {
value: key for key, value in _classes.items()
}
label_file = 'D:/dataset\coco\annotations\instances_train2017.json'
def create_detection(label_file):
#创建对象
coco = COCO(label_file)
#返回共有多少个类 [1,2,3,4,5,...90]
cat_ids = coco.getCatIds()
#返回图片的id(这个id是在.json中存储的图片id)
image_ids