Muyun99's wiki Muyun99's wiki
首页
学术搬砖
学习笔记
生活杂谈
wiki搬运
资源收藏
关于
  • 分类
  • 标签
  • 归档
GitHub (opens new window)

Muyun99

努力成为一个善良的人
首页
学术搬砖
学习笔记
生活杂谈
wiki搬运
资源收藏
关于
  • 分类
  • 标签
  • 归档
GitHub (opens new window)
  • 代码实践-目标检测

    • 基于深度学习的目标检测技术
    • mmdetection voc
    • mmdetection COCO格式数据集
    • 常用数据集简介
      • cowfits竞赛记录
    • 代码实践-图像分割

    • 代码实践-自监督学习

    • 竞赛笔记-视觉竞赛

    • 框架解析-mmlab系列

    • 讲座记录-有意思的文章集合

    • 体会感悟-产品沉思录观后有感

    • 体会感悟-摄影

    • 系列笔记-

    • 系列笔记-乐理和五线谱

    • 系列笔记-爬虫实践

    • 系列笔记-Django学习笔记

    • 系列笔记-Git 使用笔记

    • 系列笔记-网站搭建

    • 系列笔记-图卷积网络

    • 课程笔记-MIT-NULL

    • 系列笔记-OpenCV-Python

    • 系列笔记-使用 Beancount 记账

    • 系列笔记-Python设计模式

    • 系列笔记-MLOps

    • 系列笔记-Apollo自动驾驶

    • 系列笔记-PaddlePaddle

    • 系列笔记-视频操作

    • Vue+Django前后端分离开发

    • 深度学习及机器学习理论知识学习笔记

    • PyTorch Tricks

    • 学习笔记
    • 代码实践-目标检测
    Muyun99
    2021-08-03

    常用数据集简介

    # COCO格式数据集

    # 01、COCO 格式数据集标注解析

    image-20210803201311067

    分为四部分信息

    "info": {
        "description": "CowboySuit",
        "url": "http://github.com/dmlc/gluon-cv",
        "version": "1.0",
        "year": 2021,
        "contributor": "GluonCV/AutoGluon",
        "date_created": "2021/07/01"
      	},
    
    1
    2
    3
    4
    5
    6
    7
    8
    • info 主要描述数据的元信息,一般就是标注数据的版权和来源之类的
    "images": [
          {
          	"id": 11684018977583795263,
          	"file_name": "a225f95b03ce0c3f.jpg",
          	"neg_category_ids": [
            	120
          	],
          	"pos_category_ids": [
    	        69,
        	    216,
            	308,
            	433
          	],
          	"width": 1024,
          	"height": 683,
          	"source": "OpenImages"
       	  },
         ...
      	]
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    • images 是一个列表,列表里的每个实例都描述一张图像,图像比较重要的属性值如下
      • id
      • file_name
      • height
      • weight
    "annotations":[
    	  {
          	"id": 9502719,
          	"image_id": 11684018977583795263,
          	"freebase_id": "/m/032b3c",
          	"category_id": 588,
          	"iscrowd": false,
          	"bbox": [
            524.16,
            255.0,
            365.44,
            411.98
          	],
          	"area": 150553.52
       	  }
          ..
      	]
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    • annotations 则是对应图像的标注,标注比较重要的属性值如下
      • image_id
      • category_id
      • bbox: [x, y, width, height]
      • bbox 的格式是目标框左上角的坐标以及该框的宽和高
    "categories": [
        {
            "id": 87,
            "name": "belt",
            "freebase_id": "/m/0176mf"
        },
        ...
    ]
    
    1
    2
    3
    4
    5
    6
    7
    8
    • categories 则是所有的类别,比较重要的属性值如下
      • id
      • name

    # 02、COCO 格式数据集标注可视化

    # 2.1 目标框的标注可视化
    # import cv2
    import json
    import os
    
    import mmcv
    import numpy as np
    from pycocotools.coco import COCO
    
    
    def visualization_bbox(num_image, json_path, img_path):  # 需要画的第num副图片, 对应的json路径和图片路径
        with open(json_path) as annos:
            annotation_json = json.load(annos)
    
        print('the annotation_json num_key is:', len(annotation_json))  # 统计json文件的关键字长度
        print('the annotation_json key is:', annotation_json.keys())  # 读出json文件的关键字
        print('the annotation_json num_images is:', len(annotation_json['images']))  # json文件中包含的图片数量
    
        label_id_cls_dict = dict()
        for i in range(len(annotation_json['categories'][::])):
            id = annotation_json['categories'][i]['id']
            name = annotation_json['categories'][i]['name']
            label_id_cls_dict[id] = name
        print('the categories id to name dict is', label_id_cls_dict)
    
        id = annotation_json['images'][num_image - 1]['id']  # 读取图片id
        image_name = annotation_json['images'][num_image - 1]['file_name']  # 读取图片名
        image_path = os.path.join(img_path, str(image_name).zfill(5))  # 拼接图像路径
        image = mmcv.imread(image_path)
        bboxes = []
        labels = []
    
        for i in range(len(annotation_json['annotations'][::])):
            if annotation_json['annotations'][i]['image_id'] == id:
                x, y, w, h = annotation_json['annotations'][i]['bbox']  # 读取边框
                label_id = annotation_json['annotations'][i]['category_id']
                label = label_id_cls_dict[label_id]
    
                # 将左上和右下的坐标加入列表
                bboxes.append([int(x), int(y), int(x + w), int(y + h)])
                labels.append(label)
        print('The num_bbox of the display image is:', len(bboxes))
        mmcv.imshow_det_bboxes(image, np.array(bboxes), np.array(labels))
    
    
    def visualization_bbox_coco_api(num_image, json_path, img_path):
        coco = COCO(json_path)
        img = list(coco.imgs.items())[num_image][1]
    
        image_id = img['id']  # 读取图像id
        image_name = img['file_name']  # 读取图像名字
    
        image = mmcv.imread(os.path.join(img_path, image_name))  # 读取图像
        annIds = coco.getAnnIds(imgIds=image_id)
        anns = coco.loadAnns(annIds)
    
        bboxes = []
        labels = []
        for i in range(len(annIds)):
            x, y, w, h = anns[i]['bbox']  # 读取边框
            label_id = anns[i]['category_id']
            label = coco.cats[label_id]['name']
            bboxes.append([int(x), int(y), int(x + w), int(y + h)])
    
            labels.append(label)
    
        print('The num_bbox of the display image is:', len(bboxes))
        mmcv.imshow_det_bboxes(image, np.array(bboxes), np.array(labels))
    
    
    if __name__ == "__main__":
        train_json = '/home/muyun99/competition/detection/data/kaggle_cowboyoutfits/annotations.json'
        train_path = '/home/muyun99/competition/detection/data/kaggle_cowboyoutfits/images'
        for i in range(10):
            visualization_bbox(i, train_json, train_path)
            visualization_bbox_coco_api(i, train_json, train_path)
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    上次更新: 2021/08/08, 21:56:44
    mmdetection COCO格式数据集
    cowfits竞赛记录

    ← mmdetection COCO格式数据集 cowfits竞赛记录→

    最近更新
    01
    Structured Knowledge Distillation for Semantic Segmentation
    06-03
    02
    README 美化
    05-20
    03
    常见 Tricks 代码片段
    05-12
    更多文章>
    Theme by Vdoing | Copyright © 2021-2023 Muyun99 | MIT License
    • 跟随系统
    • 浅色模式
    • 深色模式
    • 阅读模式
    ×