COCO数据集names及ID json dict 格式

COCO数据集names及ID json dict 格式

dict = {
“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”: “toothbrus”
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要将VOC数据集格式转换为COCO数据集格式,可以按照以下步骤进行操作: 1. 安装Python COCO API库 COCO API库可以帮助我们处理COCO数据集格式。可以使用以下命令安装COCO API库: ``` pip install pycocotools ``` 2. 编写转换脚本 可以编写Python脚本来将VOC数据集格式转换为COCO数据集格式。下面是一个简单的脚本示例: ``` import os import json from xml.etree import ElementTree as ET from collections import defaultdict def parse_xml(xml_file): tree = ET.parse(xml_file) root = tree.getroot() size = root.find('size') width = int(size.find('width').text) height = int(size.find('height').text) objects = [] for obj in root.findall('object'): name = obj.find('name').text bbox = obj.find('bndbox') xmin = int(bbox.find('xmin').text) ymin = int(bbox.find('ymin').text) xmax = int(bbox.find('xmax').text) ymax = int(bbox.find('ymax').text) objects.append({'name': name, 'bbox': [xmin, ymin, xmax-xmin, ymax-ymin]}) return {'width': width, 'height': height, 'objects': objects} def convert_voc_to_coco(voc_dir, coco_file): images = [] annotations = [] categories = defaultdict(dict) category_id = 1 annotation_id = 1 for root, _, files in os.walk(voc_dir): for file in files: if file.endswith('.xml'): xml_file = os.path.join(root, file) image_file = os.path.splitext(xml_file)[0] + '.jpg' image_id = len(images) + 1 image = {'id': image_id, 'file_name': image_file} images.append(image) data = parse_xml(xml_file) for obj in data['objects']: category_name = obj['name'] if category_name not in categories: categories[category_name] = {'id': category_id, 'name': category_name} category_id += 1 category = categories[category_name] annotation = {'id': annotation_id, 'image_id': image_id, 'category_id': category['id'], 'bbox': obj['bbox']} annotations.append(annotation) annotation_id += 1 coco_data = {'images': images, 'annotations': annotations, 'categories': list(categories.values())} with open(coco_file, 'w') as f: json.dump(coco_data, f) if __name__ == '__main__': voc_dir = 'path/to/voc' coco_file = 'path/to/coco.json' convert_voc_to_coco(voc_dir, coco_file) ``` 在这个脚本中,我们使用`parse_xml`函数从VOC格式的XML文件中解析出图像和目标位置信息,然后使用`convert_voc_to_coco`函数将整个VOC数据集转换为COCO格式JSON文件。 3. 运行脚本 将VOC格式数据集放置在指定的目录下,然后运行上面的Python脚本即可将VOC数据集格式转换为COCO数据集格式。 ``` python voc_to_coco.py ``` 转换后的COCO格式JSON文件将保存在指定的位置。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值