YOLO V5出现RuntimeError: result type Float can‘t be cast to the desired output type long int解决方法

简介: YOLO V5出现RuntimeError: result type Float can‘t be cast to the desired output type long int解决方法

在使用YOLO框架训练自己的数据集时候,开始跑train.py,出现如下报错:

RuntimeError: result type Float can‘t be cast to the desired output type long int
Traceback (most recent call last):
  File "/home/sjh/project/yolov5-5.0/train.py", line 543, in <module>
    train(hyp, opt, device, tb_writer)
  File "/home/sjh/project/yolov5-5.0/train.py", line 304, in train
    loss, loss_items = compute_loss(pred, targets.to(device))  # loss scaled by batch_size
  File "/home/sjh/project/yolov5-5.0/utils/loss.py", line 117, in __call__
    tcls, tbox, indices, anchors = self.build_targets(p, targets)  # targets
  File "/home/sjh/project/yolov5-5.0/utils/loss.py", line 211, in build_targets
    indices.append((b, a, gj.clamp_(0, gain[3] - 1), gi.clamp_(0, gain[2] - 1)))  # image, anchor, grid indices
RuntimeError: result type Float can't be cast to the desired output type long int


由于是初次使用,并不确定是哪里的问题,只知道是跟着其他人的教程来的,经过查询,得到问题原因:


官网的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等版本在更新版本的时候出了问题


因此解决方法也明了了:修改loss.py文件


打开【utils】文件夹下的【loss.py】文件,一共需要修改两处代码,以yolov5-5.0为例:


1,大概是177行左右,可通过搜索找到下面这句代码


anchors = self.anchors[i]


将这一行其替换为

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


将其替换为

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


保存程序,重新跑train.py,便可以正常运行了

目录
相关文章
|
机器学习/深度学习 PyTorch 算法框架/工具
解决Pytorch中RuntimeError: expected scalar type Double but found Float
解决Pytorch中RuntimeError: expected scalar type Double but found Float
2420 0
|
Linux
Linux输出“Argument list too long”的解决方法
Linux输出“Argument list too long”的解决方法
171 0
Idea运行报错Error running ‘Application‘: Command line is too long的解决方法
Idea运行报错Error running ‘Application‘: Command line is too long的解决方法
127 0
|
XML 数据库 数据格式
Confluence迁移中遇到的问题(Data too long for column &#39;STRINGVAL&#39;)及解决方法
今天因为团队需要,协助帮忙看Confluence的这个问题,通过大半天的分析研究也得到不少收获,在此记录一下问题的原因以及最后的解决方案,希望对各位在迁移中碰到类似问题的大神们有所帮助。
1409 0
|
1月前
|
JSON JavaScript 前端开发
解决js中Long类型数据在请求与响应过程精度丢失问题(springboot项目中)
解决js中Long类型数据在请求与响应过程精度丢失问题(springboot项目中)
42 0
|
1月前
|
编译器 C语言
c语言中long的作用类型
c语言中long的作用类型
29 0
|
6月前
|
Java
【面试题精讲】Java超过long类型的数据如何表示
【面试题精讲】Java超过long类型的数据如何表示
|
1月前
|
存储
TS 自定义结构Long与number类型相互转换
TS 自定义结构Long与number类型相互转换
|
2月前
|
Oracle 关系型数据库 数据库
Flink Sink to Oracle 存在字段CLOB类型,如何处理错误”ORA-01461: 仅能绑定要插入LONG的LONG值“
做Flink CDC同步数据过程中,目标是Oracle数据库,其中某个字段较大被设置为CLOB类型,其中会遇到异常,”ORA-01461: 仅能绑定要插入LONG的LONG值“