【Error Logs】YoloV5出现RuntimeError: result type Float can‘t be cast to the desired output

问题描述

在训练 yolov5做简单的识别的时候出现,错误:RuntimeError: result type Float can‘t be cast to the desired output type long int。下面对解决方案进行记录。
【Error Logs】YoloV5出现RuntimeError: result type Float can‘t be cast to the desired output

问题分析

所有的操作都是按照官网的教程来实施的,但是还是出现了错误,官网的yolov5-master版本可以正常运行,但是yolov5-5.0/yolov5-6.1等版本就是不可以运行, 想着是不是由于master版本和其他分支等版本下的utils的loss.py文件是不一样的。我估计是版本更新的时候出现了问题。

问题解决

修改utils/loss.py文件中的两处内容:
第一处:

  1. loss.py中,找到
            for i in range(self.nl):
            anchors = self.anchors[i]
    
    把上面的代码改成
     for i in range(self.nl):
            anchors, shape = self.anchors[i], p[i].shape
    
  2. 在改了上面的内容之后,在找到控制点的
    indices.append((b, a, gj.clamp_(0, gain[3] - 1), gi.clamp_(0, gain[2] - 1)))  # image, anchor, grid 
    

改成:

indices.append((b, a, gj.clamp_(0, shape[2] - 1), gi.clamp_(0, shape[3] - 1)))  # image, anchor, grid

之后就可以开始训练了:
【Error Logs】YoloV5出现RuntimeError: result type Float can‘t be cast to the desired output

总结

其实我也玩不明白,也是网上东抄抄,西看看,就纯记录。

参考

https://blog.csdn.net/qq_42835363/article/details/127753543
pudn.com/news/6321667af0cde61357537e80.html

文章出处登录后可见!

已经登录?立即刷新

共计人评分,平均

到目前为止还没有投票!成为第一位评论此文章。

(0)
社会演员多的头像社会演员多普通用户
上一篇 2023年3月12日 下午8:24
下一篇 2023年3月12日 下午8:42

相关推荐