本文主要是介绍报错:ZeroDivisionError_ division by zero,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
问题:除数为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))
这篇关于报错:ZeroDivisionError_ division by zero的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!