RuntimeError: a leaf Variable that requires grad has been used in an in-place operation
Traceback (most recent call last):
File “E:\迅雷下载\向量\000、代码+数据+课件\YOLO5\yolov5-master\train.py”, line 466, in
train(hyp, opt, device, tb_writer)
File “E:\迅雷下载\向量\000、代码+数据+课件\YOLO5\yolov5-master\train.py”, line 79, in train
model = Model(opt.cfg, ch=3, nc=nc).to(device) # create 灏辨槸鍜变滑涔嬪墠璁茬殑鍒涘缓妯″瀷閭e潡
File “E:\迅雷下载\向量\000、代码+数据+课件\YOLO5\yolov5-master\models\yolo.py”, line 89, in init
self._initialize_biases() # only run once
File “E:\迅雷下载\向量\000、代码+数据+课件\YOLO5\yolov5-master\models\yolo.py”, line 149, in _initialize_biases
b[:, 4] =b[:, 4]+ math.log(8 / (640 / s) ** 2) # obj (8 objects per 640 image)
RuntimeError: a view of a leaf Variable that requires grad is being used in an in-place operation.
解决办法:
叶子节点不能执行in-place(原地)操作,因为在进行前向传播的时候得到的是叶子结点的地址,再进行反向传播的时候这个地址不变才不会报错,地址改变了就会出错
要将
a += torch.ones((1, ))
改为
a = a + torch.ones((1, ))
原代码:
for mi, s in zip(m.m, m.stride): # fromb = mi.bias.view(m.na, -1) # conv.bias(255) to (3,85)b[:, 4]+= math.log(8 / (640 / s) ** 2) # obj (8 objects per 640 image)b[:, 5:]+= math.log(0.6 / (m.nc - 0.99)) if cf is None else torch.log(cf / cf.sum()) # clsmi.bias = torch.nn.Parameter(b.view(-1), requires_grad=True)
本错误的解决办法:
for mi, s in zip(m.m, m.stride): # fromb = mi.bias.view(m.na, -1) # conv.bias(255) to (3,85)bb = b[:, 4]bb = bb + math.log(8 / (640 / s) ** 2) # obj (8 objects per 640 image)bbb = b[:, 5:]bbb = bbb + math.log(0.6 / (m.nc - 0.99)) if cf is None else torch.log(cf / cf.sum()) # clsmi.bias = torch.nn.Parameter(b.view(-1), requires_grad=True)
RuntimeError: a leaf Variable that requires grad has been used in an in-place operation相关推荐
- RuntimeError:a leaf Variable that requires grad has been used in an in-place
原文链接:https://blog.csdn.net/weixin_43056332/article/details/115188116 记录一下训练yolov5碰到的问题 RuntimeError: ...
- RuntimeError: a view of a leaf Variable that requires grad is being used in an in-place operation.
跑yolov5的代码时,pytorch遇到<>RuntimeError: a view of a leaf Variable that requires grad is being use ...
- 报错 RuntimeError: a view of a leaf Variable that requires grad is being used in an in-place operation
报错大致意思是不能对在计算图中带梯度的变量进行操作 源代码 def anim(i):# update SMBLDcur_beta_idx, cur_step = i // num_steps, i % ...
- a leaf Variable that requires grad has been used in an in-place operation
a leaf Variable that requires grad has been used in an in-place operation 这个是因为写成了x+=2, 改为y = x + 2 ...
- A leaf Variable that requires grad is being used in an in-place operation
错误原因: 计算图中的叶子节点不能直接进行内置运算,防止影响计算图的反向传播运算.如果非要改变叶子节点data的值,可以直接对data属性调用内置运算,这样不会记录在计算图当中. 解决方案: 1.把梯 ...
- a view of a leaf Variable that requires grad is being used in an in-place operation.
问题背景: 可以尝试的办法: 将pytorch1.8 降低到 1.7
- RuntimeError: Can‘t call numpy() on Variable that requires grad. Use var.detach().numpy()
1. 问题描述 如题,将PyTorch Tensor类型的变量转换成numpy时报错: RuntimeError: Can't call numpy() on Variable that requir ...
- leaf Variable、requires_grad、grad_fn的含义以及它们之间的关系
文章内容皆为个人理解,不足之处敬请指正. 1.requires_grad requires_grad是pytorch中tensor的一个属性,如果requires_grad=True,在进行反向传播的 ...
- 错误RuntimeError: Invalid DISPLAY variable
在使用ubuntu系统时,远程连接服务器,并没有GUI图形界面的情况下: python3.6.2 ubuntu系统运行python代码出现错误: RuntimeError: Invalid DISPL ...
最新文章
- linux下截屏工具
- IE8不支持jQuery问题
- C语言之基本算法32—鞍点
- ftp服务器新建虚拟目录,ftp服务器 虚拟目录
- 达摩院送你100万,请坚持“看月亮”
- SAP License:在产品结算参数设置
- 新海诚动画背景简单娱乐分析
- 中文HanLp分词入门
- 微信中location.reload失效
- 【Java面试题】40 你所知道的集合类都有哪些?主要方法?
- 前端实现用户自定义建表_Excel、SQL、Python分别实现行列转换
- 数据重塑_人工智能能否重塑全球力量平衡?
- windows10 配置深度学习环境
- 浙江移动无线dns服务器地址,首选dns_浙江省宁波市(中国移动)首选dns是什么,备选dns是什么...
- 苹果六电池_苹果7P更换电池教程,小白也能动手更换
- 计算机屏幕出现条纹w7,电脑屏幕出现条纹,教您电脑屏幕出现条纹怎么办
- Android之ListView展示多类型的条目
- c#、java、钉钉、微信小程序、APP采集modbus TCP协义的PLC数据
- mysql下日志_浅谈mysql下日志记录
- CSS基础-03-字体和文本样式