VOC数据集解析 VOC2007解析

 

 

VOC数据是 PASCAL VOC Challenge 用到的数据集,官网:http://host.robots.ox.ac.uk/pascal/VOC/

备注:VOC数据集常用的均值为:mean_RGB=(122.67891434, 116.66876762,  104.00698793)

pytorch上通用的数据集的归一化指标为:mean=(0.485, 0.456,  0.406) ,std=(0.229, 0.224, 0.225)

这里以常用的 VOC2007数据集 作为代表来讲解一下VOC数据集

1.下载数据

官网:http://host.robots.ox.ac.uk/pascal/VOC/voc2007/index.html

训练集/验证集http://host.robots.ox.ac.uk/pascal/VOC/voc2007/VOCtrainval_06-Nov-2007.tar

DevKithttp://host.robots.ox.ac.uk/pascal/VOC/voc2007/VOCdevkit_08-Jun-2007.tar

带有标记的测试集http://host.robots.ox.ac.uk/pascal/VOC/voc2007/VOCtest_06-Nov-2007.tar

这里说明一下,VOC官方给出的数据集中,只有VOC2007是给出了带有标记的测试集的,

其他年份的数据集是没有给测试集test set的,只给的有带标记的验证集 annotatied validation set

 

至于训练集train set、验证集validation set 和 测试集 test set 分别是用来干什么的,属实是没有必要在这里讲...常识性知识

 

那么下载完成后得到如下压缩包:

分开来讲这三个包:

  • 22
    点赞
  • 79
    收藏
    觉得还不错? 一键收藏
  • 9
    评论
VOC数据集转换为COCO数据集需要进行以下步骤: 1. 将VOC数据集中的图片和标注文件分别放在两个文件夹中,例如:images文件夹和annotations文件夹。 2. 安装pycocotools库,该库可以通过pip install pycocotools命令进行安装。 3. 创建一个空的COCO数据集,可以使用以下代码: ``` from pycocotools.coco import COCO coco = COCO() ``` 4. 遍历VOC数据集中的每个标注文件,将其转换为COCO数据集中的格式,并添加到COCO数据集中。以下是一个示例代码: ``` import os import xml.etree.ElementTree as ET from pycocotools.coco import COCO from pycocotools import mask as maskUtils # 初始化COCO数据集 coco = COCO() # 添加类别 classes = ['person', 'car', 'bus', 'truck'] for i, cls in enumerate(classes): coco.add_category({'id': i + 1, 'name': cls}) # 遍历VOC数据集中的每个标注文件 annotations_dir = 'annotations' for filename in os.listdir(annotations_dir): if not filename.endswith('.xml'): continue # 解析标注文件 tree = ET.parse(os.path.join(annotations_dir, filename)) root = tree.getroot() # 获取图片信息 image_id = int(root.find('filename').text.split('.')[0]) width = int(root.find('size/width').text) height = int(root.find('size/height').text) # 添加图片信息 coco.add_image({ 'id': image_id, 'width': width, 'height': height, 'file_name': f'{image_id}.jpg' }) # 遍历标注信息 for obj in root.findall('object'): cls = obj.find('name').text bbox = obj.find('bndbox') x1 = int(bbox.find('xmin').text) y1 = int(bbox.find('ymin').text) x2 = int(bbox.find('xmax').text) y2 = int(bbox.find('ymax').text) # 添加标注信息 coco.add_annotation({ 'id': len(coco.dataset['annotations']) + 1, 'image_id': image_id, 'category_id': classes.index(cls) + 1, 'bbox': [x1, y1, x2 - x1, y2 - y1], 'area': (x2 - x1) * (y2 - y1), 'iscrowd': 0, 'segmentation': maskUtils.frPyObjects([[x1, y1, x2, y1, x2, y2, x1, y2]], height, width) }) ``` 5. 将COCO数据集保存为JSON格式的文件,可以使用以下代码: ``` import json with open('coco.json', 'w') as f: json.dump(coco.dataset, f) ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值