问题:除数为0
原代码错误来源
# 归一化 , 保留6位小数
w = round(w / img_w, 6)
h = round(h / img_h, 6)
cx = round(cx / img_w, 6)
cy = round(cy / img_h, 6)
# print(cls_id, cx, cy, w, h)
# 结果保存到数据labels文件夹中的txt文件
out_file.write(str(cls_id) + " " + str(cx) + " " + str(cy) +
" " + str(w) + " " + str(h) + '\n')
改为
try:
# 归一化 , 保留6位小数
w = round(w / img_w, 6)
h = round(h / img_h, 6)
cx = round(cx / img_w, 6)
cy = round(cy / img_h, 6)
# print(cls_id, cx, cy, w, h)
# 结果保存到数据labels文件夹中的txt文件
out_file.write(str(cls_id) + " " + str(cx) + " " + str(cy) +
" " + str(w) + " " + str(h) + '\n')
except ZeroDivisionError as e:
in_file.close()
os.remove(annotations_path % (image_id))