一步真实解决RuntimeError: result type Float can‘t be cast to the desired output type long int

问题描述:

在使用YOLO框架训练自己的数据集时候,你是不是出现了这个问题?

一步真实解决RuntimeError: result type Float can‘t be cast to the desired output type long int

RuntimeError: result type Float can’t be cast to the desired output type long int

明明自己【data】下的yaml文件,【models】下网络结构等文件设置与修改都是按照教程来的

可还是出现了问题?这是怎么回事?

起初我也遇到了这个问题,但是经过思考,终于找到了问题的根源:

官网的yolov5-master版本可以正常运行,但是yolov5-5.0/yolov5-6.1等版本就是不可以运行

这是因为yolov5-master版本和yolov5-5.0/yolov5-6.1等版本下的【utils】中的【loss.py】文件是不一样的,大概是yolov5-5.0/yolov5-6.1等版本在更新版本的时候出了问题

不过,我已经总结出了解决这个问题办法,详细看下一章节内容吧~~~

; 问题解决:

修改【utils】中的【loss.py】里面的两处内容

1.打开你的【utils】文件下的【loss.py】

2.按【Ctrl】+【F】打开搜索功能,输入【for i in range(self.nl)】找到下面的一行内容:

一步真实解决RuntimeError: result type Float can‘t be cast to the desired output type long int

(上面的代码在【loss.py】的后半部分)

将下面的代码替换掉上图中的红圈部分:

 anchors, shape = self.anchors[i], p[i].shape

替换之后的效果是这样的:

一步真实解决RuntimeError: result type Float can‘t be cast to the desired output type long int

3.按【Ctrl】+【F】打开搜索功能,输入【indices.append】找到下面的一行内容:

一步真实解决RuntimeError: result type Float can‘t be cast to the desired output type long int

(上面的代码在【loss.py】的最后部分,具体位置在上一处搜索位置的下面10行左右)

将下面的代码替换掉上图中的红圈部分:

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

一步真实解决RuntimeError: result type Float can‘t be cast to the desired output type long int

4.保存刚才的两个替换操作

一步真实解决RuntimeError: result type Float can‘t be cast to the desired output type long int

6.如果你还是跑不通,可以看最后的小提示,可能会有你的问题!

【更新】小提示

如果你按照我的方法改了指定的代码,还出现了下面的问题?

一步真实解决RuntimeError: result type Float can‘t be cast to the desired output type long int

那么你是在修改下面地方时,没有将【anchors】和下面的【gain】对齐!!!

一步真实解决RuntimeError: result type Float can‘t be cast to the desired output type long int

打开【loss,.py】对齐下代码就可以了!完美解决小小粗心bug~

到这,就已经解决了问题。欢迎关注蓝胖胖,咱们一起解决BUG~~~

Original: https://blog.csdn.net/Thebest_jack/article/details/125649451
Author: 蓝胖胖▸
Title: 一步真实解决RuntimeError: result type Float can‘t be cast to the desired output type long int

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/542791/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球