目标检测coco数据集点滴介绍

目标检测coco数据集点滴介绍

1.  COCO数据集介绍

MS COCO 是google 开源的大型数据集, 分为目标检测、分割、关键点检测三大任务, 数据集主要由图片和json 标签文件组成。 coco数据集有自带COCO API,方便对json文件进行信息读取。本博客介绍是目标检测数据集格式的制作。

COCO通过大量使用Amazon Mechanical Turk来收集数据。COCO数据集现在有3种标注类型:object instances(目标实例), object keypoints(目标上的关键点), 和image captions(看图说话),使用JSON文件存储。

2.  MSCOCO数据集数据结构{

"images":

[

{"file_name":"cat.jpg","id":1,"height":1000,"width":1000},

{"file_name":"dog.jpg","id":2,"height":1000,"width":1000},

...

]

"annotations":

 [

{"image_id":1,"bbox":[100.00,200.00,10.00,10.00],"category_id":1}

{"image_id":2,"bbox":[150.00,250.00,20.00,20.00],"category_id":2}

...

]

"categories":

 [

{"id":0,"name":"bg"}

{"id":1,"name":"cat"}

{"id":1,"name":"dog"}

...

]

}

标注文件中,"images" 关键字对应图片信息,"annotations" 关键字对应标注信息,"categories" 对应类别信息: "images": 该关键字对应的数据中,每一项对应一张图片,"file_name"对应图片名称,"id"对应图片序号,"height"和"width"分别对应图像的高和宽。 "annotations": 该关键字对应的数据中,每一项对应一条标注,"image_id"对应图片序号,"bbox"对应标注矩形框,顺序为[x, y, w, h],分别为该矩形框的起始点x坐标,起始点y坐标,宽、高。"category_id"对应类别序号。 "categories": 该关键字对应的数据中,每一项对应一个类别,"id"对应类别序号,"name"对应类别名称。

关键字关联说明: 1."annotations"中的元素通过"image_id"关联图像,比如"image_id":2,该条标注信息对应"images"中"id"为2的图像。 2."annotations"中的元素通过"category_id"关联类别,比如"category_id":2,该条标注信息对应"categories"中"id"为2的类别。

例: 在上面列出的数据结构中

这条标注信息通过"image_id"可以找到对应的图像为"cat.jpg",通过"category_id"可以找到对应的类别为"cat"

背景图片说明:
"annotations"中的元素,"category_id":0对应的是背景。当且仅当一张图片对应的所有annotations中,"category_id"都为0,该图片为背景图片。

3.  COCO数据集json文件,分类和id

coco目标检测数据集标注目标信息采用的是数据格式是json,其内容本质是一种字典结构,字典堆栈和列表信息内容维护。

coco里面的id和类名字对应:总共80类,但id号到90!

coco_id_name_map={1: 'person', 2: 'bicycle', 3: 'car', 4: 'motorcycle', 5: 'airplane',                   6: 'bus', 7: 'train', 8: 'truck', 9: 'boat', 10: 'traffic light', 11: 'fire hydrant', 13: 'stop sign', 14: 'parking meter', 15: 'bench', 16: 'bird', 17: 'cat', 18: 'dog', 19: 'horse', 20: 'sheep', 21: 'cow', 22: 'elephant', 23: 'bear', 24: 'zebra', 25: 'giraffe', 27: 'backpack', 28: 'umbrella', 31: 'handbag', 32: 'tie', 33: 'suitcase', 34: 'frisbee', 35: 'skis', 36: 'snowboard', 37: 'sports ball', 38: 'kite', 39: 'baseball bat', 40: 'baseball glove', 41: 'skateboard', 42: 'surfboard', 43: 'tennis racket', 44: 'bottle', 46: 'wine glass', 47: 'cup', 48: 'fork', 49: 'knife', 50: 'spoon', 51: 'bowl', 52: 'banana', 53: 'apple', 54: 'sandwich', 55: 'orange', 56: 'broccoli', 57: 'carrot', 58: 'hot dog', 59: 'pizza', 60: 'donut', 61: 'cake', 62: 'chair', 63: 'couch', 64: 'potted plant', 65: 'bed', 67: 'dining table', 70: 'toilet', 72: 'tv', 73: 'laptop', 74: 'mouse', 75: 'remote', 76: 'keyboard', 77: 'cell phone', 78: 'microwave', 79: 'oven', 80: 'toaster', 81: 'sink', 82: 'refrigerator', 84: 'book', 85: 'clock', 86: 'vase', 87: 'scissors', 88: 'teddy bear', 89: 'hair drier', 90: 'toothbrush'}

打开json文件:

 with open(json_path,'r') as load_f:

    load_dict = json.load(load_f)

里面协议是这样的,annotations下面是每一个box的标注信息,包括分割的,当前框使用目标框,image_id,categogy_id。

因此要想获得整个数据集信息,必须遍历整个box信息,将其进行统计分配。

4.  COCO数据集性能指标

COCO 提供了 12 种用于衡量目标检测器性能的评价指标.

Recall   召回率(查全率)。表示正确识别物体A的个数占测试集中物体A的总个数的百分数Recall = TP / (TP+FN)

Precision 精确率(查准率)。表示正确识别物体A的个数占总识别出的物体个数n的百分数Precision = TP / (TP+FP)

fp :false positive误报,即预测错误

fn :false negative漏报,即没有预测到

tp:true positive

tn:true negative

iou:intersection-over-union

Accuracy  准确率。正确分类的样本数除以所有的样本数,正确率越高,分类器越好。Accuracy=(TP+TN)/ (TP+TN+FP+FN)

以上介绍都是基于2分类的,并不是多分类的

 以下12个指标用于表征COCO上物体检测器的性能:

 Average Precision (AP):

AP                              % AP at IoU=0.50:0.05:0.95 (primary challenge metric)

APIoU=.50                   % AP at IoU=0.50 (PASCAL VOC metric)

APIoU=.75                   % AP at IoU=0.75 (strict metric)

AP Across Scales:

APsmall                       % AP for small objects: area < 322

APmedium                   % AP for medium objects: 322 < area < 962

APlarge                        % AP for large objects: area > 962

Average Recall (AR):

ARmax=1                     % AR given 1 detection per image

ARmax=10                   % AR given 10 detections per image

ARmax=100                 % AR given 100 detections per image

AR Across Scales:

ARsmall                       % AR for small objects: area < 322

ARmedium                   % AR for medium objects: 322 < area < 962

ARlarge                        % AR for large objects: area > 962

原文地址:https://www.cnblogs.com/wujianming-110117/p/12610141.html