bdd100k数据集格式转coco格式

最近在学习使用mmdetection,需要使用bdd100k数据集来训练网络,但是官网下载的数据集格式不是coco数据集,得自己转换数据集格式。

一、bdd100k数据集下载

数据集下载地址:https://dl.cv.ethz.ch/bdd100k/data/

我下载了下面这些数据集,我们主要是对bdd100k_det_20_labels_trainval.zip这个文件夹进行操作。
在这里插入图片描述
解压bdd100k_det_20_labels_trainval.zip,记住解压路径。

二、bdd100k转coco脚本下载

BDD100K文档中有提到数据格式转换,但我没看懂,我选择使用.py转换。
在这里插入图片描述

github链接:
https://github.com/ucbdrive/bdd100k/tree/e0e54415d8c2659d606ef0721925aa5c09822732
这个代码官方现在好像不维护了(四年没更新了),但是我使用正常。

百度网盘链接:https://pan.baidu.com/s/1W-G_DPEnEqckoYls68TLnw?pwd=1111

三、脚本使用

找到转换脚本文件,并在路径框输入cmd
在这里插入图片描述
打开命令行后,输入下面的命令,例如:
在这里插入图片描述

python bdd2coco.py --label_dir bdd数据集label文件路径(不带文件名称) --save_path coco数据集保存位置(不带文件名称)

报错

Traceback (most recent call last):
  File "bdd100k\bdd2coco.py", line 103, in <module>
    bdd2coco_detection(attr_id_dict, train_labels, out_fn)
  File "bdd100k\bdd2coco.py", line 41, in bdd2coco_detection
    for label in i['labels']:
KeyError: 'labels'
  • 11
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
BDD100K是一个包含车辆行驶场景的大型数据集,其中包括图像、视频和语义分割标注。如果你想将BDD100K数据集换为YOLO格式,可以按照以下步骤进行: 1. 下载BDD100K数据集并解压缩。 2. 安装Python3和OpenCV。 3. 创建一个新的文件夹,用于存储YOLO格式的标注文件和图像。 4. 在该文件夹中创建一个名为“classes.txt”的文件,并在其中列出数据集中所有可能的类别。 5. 打开终端或命令提示符窗口,导航到BDD100K数据集文件夹。 6. 运行以下Python脚本,将BDD100K标注换为YOLO格式: ```python import os import cv2 # Define the classes classes = ["car", "truck", "bus", "person", "bike", "motor", "traffic light", "traffic sign"] # Open classes file with open("classes.txt", "w") as f: for i, c in enumerate(classes): f.write(f"{c}\n") # Traverse the image directory and convert the annotations for dirpath, dirnames, filenames in os.walk("bdd100k/images/100k/train"): for filename in filenames: if filename.endswith(".jpg"): # Load the image img = cv2.imread(os.path.join(dirpath, filename)) # Load the annotation file anno_file = os.path.join("bdd100k/labels", dirpath.split("/")[-1], filename.replace(".jpg", ".txt")) with open(anno_file, "r") as f: annotations = f.readlines() # Create a new annotation file with open(os.path.join("yolo_labels", filename.replace(".jpg", ".txt")), "w") as f: for annotation in annotations: # Parse the annotation values = annotation.split(" ") x, y, w, h = [float(v) for v in values[2:6]] x_center = x + w / 2 y_center = y + h / 2 class_id = classes.index(values[0]) # Convert to YOLO format img_h, img_w, _ = img.shape x_center /= img_w y_center /= img_h w /= img_w h /= img_h f.write(f"{class_id} {x_center} {y_center} {w} {h}\n") ``` 7. 运行脚本后,YOLO格式的标注文件将存储在名为“yolo_labels”的文件夹中,并且每个图像都有一个相应的标注文件。 注意:这个示例只是一个基本的换脚本,可能需要根据实际情况进行更改。例如,如果您的数据集包含其他类别或具有不同的分辨率,则需要相应地更新代码。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值