Asi*_*sim 2 opencv normalization python-3.x yolov5
我正在自定义数据集上训练 yolov5 并收到非标准化标签错误。注释有 x,y 和 w,h,这意味着边界框存在于 (x,y) 到 (x+w,y+h) 之间。我正在使用 cv2 矩形函数来显示图像上的边界框,它正在创建完美的边界框。我知道我必须将原始标签转换为标准化中心 x、中心 y、宽度和高度值。我正在下面这样做:
x2=x+w # x,y, w and h are given
y2=y1+h
xc=x+w/2
yc=y+h/2
xc=xc/width # normalize from 0-1. Width and height are image's width and height
yc=yc/height
wn=w/width # normalize the width from 0-1
hn=h/height
label_file.write(f"{category_idx} {xc} {yc} {wn} {hn}\n")
Run Code Online (Sandbox Code Playgroud)
但是当我在文本文件中写入这些标签并运行 yolov5 训练时,它会给出以下断言错误:
assert (l[:, 1:] <= 1).all(), 'non-normalized or out of bounds coordinate labels: %s' % file # throws assertion error
AssertionError: non-normalized or out of bounds coordinate labels: /Raja/Desktop/yolov5/data/roi/labels/train/10.txt
Run Code Online (Sandbox Code Playgroud)
10.txt文件如下:
1 0.7504960317460317 0.3599537037037037 0.16765873015873023 0.059193121693121686
4 0.21664186507936506 0.3316798941798942 0.19122023809523808 0.0443121693121693
5 0.47879464285714285 0.2931547619047619 0.32663690476190477 0.04728835978835977
0 0.265625 0.47701719576719576 0.3045634920634921 0.0889550264550264
1 0.17671130952380953 0.5830026455026455 0.13120039682539683 0.07275132275132279
2 0.5212053571428572 0.7986111111111112 0.15550595238095244 0.07407407407407407
2 0.7638888888888888 0.8009259259259259 0.16121031746031755 0.07275132275132279
Run Code Online (Sandbox Code Playgroud)
我使用 cv2 矩形函数在图像上显示边界框,它正在创建完美的边界框,如下图所示:
cv2.rectangle(temp_img,(int(x), int(y)),(int(x+w), int(y+h)),color=(0, 255, 0),thickness=2)
Run Code Online (Sandbox Code Playgroud)
我试图在网上找到解决方案,例如GitHub 上提出的这个问题,但还没有找到任何东西。谁能告诉我我在这里做错了什么?我认为将原始标签转换为 0-1 标准化标签时存在问题,因为断言指出它已找到非标准化标签。任何帮助将不胜感激!
小智 6
x_center和除以width图像宽度,然后将y_center和height除以图像高度。例子:
\nYOLOv5格式: f"{category_idx} {x1 + bbox_width / 2} {y1 + bbox_height / 2} {bbox_width} {bbox_height}\\n"
\n| 归档时间: |
|
| 查看次数: |
2407 次 |
| 最近记录: |