Yolov5不支持分段标签,我需要将它转换成正确的格式。
您将如何将此转换为yolo格式?
"boundingPoly": {
"normalizedVertices": [{
"x": 0.026169369
}, {
"x": 0.99525446
}, {
"x": 0.99525446,
"y": 0.688811
}, {
"x": 0.026169369,
"y": 0.688811
}]
}yolo格式如下所示
0 0.588196 0.474138 0.823607 0.441645
<object-class> <x> <y> <width> <height>发布于 2021-12-21 00:34:52
在我们的评论后,我有足够的信息来回答你的问题。这是来自的输出。normalizedVertices类似于YOLO格式,因为它们是“规范化”的,这意味着坐标是在0到1之间缩放的,而不是从1到n的像素。在YOLO格式中,第2列和第3列中的X和Y值指的是包围框的中心,而不是其中的一个角。
下面是一个代码片段,它将在https://ghostbin.com/hOoaz/raw上示例成以下YOLO格式的字符串'0 0.5080664305 0.5624289849999999 0.9786587390000001 0.56914843‘
#Sample annotation output
json_annotation = """
[
{
"mid": "/m/01bjv",
"name": "Bus",
"score": 0.9459266,
"boundingPoly": {
"normalizedVertices": [
{
"x": 0.018737061,
"y": 0.27785477
},
{
"x": 0.9973958,
"y": 0.27785477
},
{
"x": 0.9973958,
"y": 0.8470032
},
{
"x": 0.018737061,
"y": 0.8470032
}
]
}
}
]
"""
import json
json_object = json.loads(json_annotation, strict=False)
#Map all class names to class id
class_dict = {"Bus": 0}
#Get class id for this record
class_id = class_dict[json_object[0]["name"]]
#Get the max and min values from segmented polygon points
normalizedVertices = json_object[0]["boundingPoly"]["normalizedVertices"]
max_x = max([v['x'] for v in normalizedVertices])
max_y = max([v['y'] for v in normalizedVertices])
min_x = min([v['x'] for v in normalizedVertices])
min_y = min([v['y'] for v in normalizedVertices])
width = max_x - min_x
height = max_y - min_y
center_x = min_x + (width/2)
center_y = min_y + (height/2)
yolo_row = str(f"{class_id} {center_x} {center_y} {width} {height}")
print(yolo_row)如果您想要训练一个YOLO模型,还需要执行几个步骤:您需要在特定的文件夹结构中设置图像和注释。但这将帮助您转换注释。
https://stackoverflow.com/questions/70420807
复制相似问题