【问题标题】:How to convert PASCAL VOC to YOLO如何将 PASCAL VOC 转换为 YOLO
【发布时间】:2021-02-11 08:10:37
【问题描述】:

我试图开发一些在格式之间转换注释的方法,但很难找到信息,但我有:

这个是PASCAL VOC

<width>800</width>
<height>450</height>
<depth>3</depth>
<bndbox>
    <xmin>474</xmin>
    <ymin>2</ymin>
    <xmax>726</xmax> <!-- shape_width = 252  -->
    <ymax>449</ymax> <!-- shape_height = 447 -->
</bndbox>

转换为 YOLO 暗网

2 0.750000 0.501111 0.315000 0.993333

注意首字母2这是一个类别

【问题讨论】:

标签: training-data yolo coco voc


【解决方案1】:

使用一些数学:(也可以对 COCO 有用)

categ_index [(xmin + xmax) / 2 / image_width] [(ymin + ymax) / 2 / image_height] [(xmax - xmin) / image_width] [(ymax  - ymin) / image_height]

在js代码中

const categ_index = 2;

const { width: image_width, height: image_height } = {
  width: 800,
  height: 450,
};

const { xmin, ymin, xmax, ymax } = {
  xmin: 474,
  ymin: 2,
  xmax: 727,
  ymax: 449,
};

const x_coord = (xmin + xmax) / 2 / image_width;

const y_coord = (ymin + ymax) / 2 / image_height;

const shape_width = (xmax - xmin) / image_width;

const shape_height = (ymax - ymin) / image_height;

console.log(`${categ_index} ${x_coord.toFixed(7)} ${y_coord.toFixed(7)} ${shape_width.toFixed(7)} ${shape_height.toFixed(7)}`);

// output
// 2 0.7506250 0.5011111 0.3162500 0.9933333

【讨论】:

    【解决方案2】:

    我和我的同学创建了一个名为 PyLabel 的 python 包来帮助其他人完成这项任务和其他标记任务。

    这是从 voc 转换为 coco 的基本代码:

    !pip install pylabel
    from pylabel import importer
    dataset = importer.ImportVOC(path=path_to_annotations)
    dataset.exporter.ExportToYoloV5() 
    

    你可以在这里找到示例笔记本和源代码https://github.com/pylabel-project/pylabel

    【讨论】:

      【解决方案3】:

      我使用下面的 sn-p 将 Pascal_VOC 转换为 YOLO。 Yolo 使用标准化坐标,因此拥有图像的高度和宽度很重要。否则无法计算。

      这是我的 sn-p:

      # Convert Pascal_Voc bb to Yolo
      def pascal_voc_to_yolo(x1, y1, x2, y2, image_w, image_h):
          return [((x2 + x1)/(2*image_w)), ((y2 + y1)//(2*image_h)), (x2 - x1)/image_w, (y2 - y1)/image_h]
      

      我写了一篇关于对象检测格式以及如何转换它们的文章。您可以查看我在 Medium 上的博文:https://christianbernecker.medium.com/convert-bounding-boxes-from-coco-to-pascal-voc-to-yolo-and-back-660dc6178742

      玩得开心!

      【讨论】:

        猜你喜欢
        • 2021-09-15
        • 2023-01-26
        • 1970-01-01
        • 2017-12-07
        • 2015-10-14
        • 2017-08-15
        • 2018-10-09
        • 1970-01-01
        • 2018-06-22
        相关资源
        最近更新 更多