问题

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::Halffloat 数据类型不一致,那么改过来就行了。

解决

检查一下 box[i]x[i, j + 5, None]j[:, None].float() 的类型,可以知道:

  • box[i] 的类型是 torch.float16
  • x[i, j + 5, None] 的类型是 torch.float16
  • j[:, None].float() 的类型是 torch.float32

解决方式 是将 j[:, None].float() 改为 j[:, None].half()

Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐