首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将PASCAL VOC转换为YOLO

如何将PASCAL VOC转换为YOLO
EN

Stack Overflow用户
提问于 2020-10-28 21:39:04
回答 3查看 5.6K关注 0票数 3

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

这个是PASCAL VOC

代码语言:javascript
复制
<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暗网

代码语言:javascript
复制
2 0.750000 0.501111 0.315000 0.993333

注意初始的2,它是一个类别

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2020-10-28 21:39:04

使用一些数学:(对可可也是有用的)

代码语言:javascript
复制
categ_index [(xmin + xmax) / 2 / image_width] [(ymin + ymax) / 2 / image_height] [(xmax - xmin) / image_width] [(ymax  - ymin) / image_height]

在js代码中

代码语言:javascript
复制
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

票数 3
EN

Stack Overflow用户

发布于 2021-10-27 03:22:36

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

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

代码语言:javascript
复制
!pip install pylabel
from pylabel import importer
dataset = importer.ImportVOC(path=path_to_annotations)
dataset.exporter.ExportToYoloV5() 

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

票数 5
EN

Stack Overflow用户

发布于 2022-02-08 10:32:38

我使用以下代码片段将Pascal_VOC转换为YOLO。Yolo使用归一化坐标,因此图像的高度和宽度非常重要。否则你就不能算了。

这是我的片段:

代码语言:javascript
复制
# 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]

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

玩得开心!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64581692

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档