Expected object of scalar type c10::Half but got scalar type float for sequence element 2.
问题Traceback (most recent call last):File "test.py", line 324, in <module>save_conf=opt.save_conf,File "test.py", line 124, in testoutput = non_max_suppression(inf_out, conf_thres=conf_thres, iou
·
问题
Traceback (most recent call last):
File "test.py", line 324, in <module>
save_conf=opt.save_conf,
File "test.py", line 124, in test
output = non_max_suppression(inf_out, conf_thres=conf_thres, iou_thres=iou_thres, labels=lb)
File "/home/yolov5/utils/general.py", line 373, in non_max_suppression
x = torch.cat((box[i], x[i, j + 5, None], j[:, None].float()), 1)
RuntimeError: Expected object of scalar type c10::Half but got scalar type float for sequence element 2.
分析
问题中提到 c10::Half 与 float 数据类型不一致,那么改过来就行了。
解决
检查一下 box[i]、x[i, j + 5, None]、j[:, None].float() 的类型,可以知道:
box[i]的类型是torch.float16x[i, j + 5, None]的类型是torch.float16j[:, None].float()的类型是torch.float32
解决方式 是将 j[:, None].float() 改为 j[:, None].half()
更多推荐

所有评论(0)