这个错误源于Pytorch对Tensor进行 backward() 自动求导时,该Tensor的requires_grad为False,requires_grad参数指定是否记录对Tensor的操作以便计算梯度。在创建Tensor时该参数默认为False,需要手动设置如下
loss = torch.zeros(1, requires_grad=True)
也可以通过loss.requires_grad_(True)设置。有篇文章详细介绍了相关原理,引用一下链接。

Pytorch报错:element 0 of tensors does not require grad and does not have a grad_fn相关推荐

  1. element 0 of tensors does not require grad and does not have a grad_fn

    element 0 of tensors does not require grad and does not have a grad_fn 这个是因为requires_grad=False,应该为t ...

  2. 使用pytorch的loss.backward()时,出现element 0 of tensors does not require grad and does not have a grad_fn

    仅作为记录,大佬请跳过. 用loss.requires_grad_(True) 是因为loss没有设置梯度(所以不能反向传播)(loss的数据类型是tensor) 设置梯度后即可,展示: 参考 pyt ...

  3. Pytorch_Geometric(PyG)使用DataLoader报错RuntimeError: Sizes of tensors must match except in dimension 0.

    使用Pytorch_Geometric(PyG)时构建DataLoader,从DataLoader获取样本Batch时报错:RuntimeError: Sizes of tensors must ma ...

  4. pycharm安装pytorch报错 提示系列问题 torch 包找不到因为pip版本低,结果升级了pip从19.3到20.2 4又提示高版不支持torch安装

    pycharm安装pytorch报错 提示系列问题  torch 包找不到因为pip版本低,结果升级了pip从19.3到20.2 4又提示高版不支持torch安装 DEPRECATION: The - ...

  5. pytorch报错Unable to get repr for

    pytorch报错Unable to get repr for 标签出现了-1,2或者其他值,loss计算之后, 报错:CUDA error: device-side assert triggered ...

  6. 安装pytorch报错及解决

    环境,win10,64位,Anaconda4.10.3,Cuda 9.2.148,cudnn应该为v7.4.2.24 其中在Anaconda中好像安装tensorflow-gpu 1.9 ,pytho ...

  7. Pytorch | 报错The given NumPy array is not writeable,and PyTorch does not support non-writeable tensor

    Pytorch | 报错 The given NumPy array is not writeable,and PyTorch does not support non-writeable tenso ...

  8. DDP报错::RuntimeError: Expected all tensors to be on the same device, but found at least two devic

    DDP报错 RuntimeError: Expected all tensors to be on the same device, but found at least two devices, c ...

  9. PyTorch 报错:TypeError: exceptions must derive from BaseException

    项目场景: PyTorch 报错:TypeError: exceptions must derive from BaseException 其实是个低级错误,我个人认为是因为没有找到要运行的载体. 问 ...

最新文章

  1. Javadoc注释规范
  2. 第三日:继续恢复网站
  3. duilib控件的一些属性
  4. A Convolutional Neural Network for Modelling Sentences阅读笔记
  5. Fiori UI上my contact加了Dr. 后搜索不出数据的奇怪问题
  6. _Linux软件安装
  7. Android应用开发系列课程------ViewPager与ViewFlipper较量
  8. mysql ignore space_MySQL日志存储空间满引发的错误
  9. jsvascript 学习 二 操作符
  10. 我从佛学里悟到的自由
  11. 2006年 上半年 网络管理员 下午试卷
  12. 23个超流行的jQuery相册插件收集
  13. C# 面向对象初级 (参考传智播客视频)
  14. mac install torch0.4.1
  15. 寒假学习之stm32(15)----DMA(direct memory access)
  16. CentOS 7查看源代码
  17. 大数据和人工智能的关系,超全解析 1
  18. 文本文件里如何快速在每行头尾都加上指定的内容---正则表达式(一)
  19. java mybatis多层collection嵌套查询
  20. 目标跟踪方法--基于区域跟踪

热门文章

  1. 浏览器内核及内核介绍
  2. QQ2010 Beta 抢先下载【官方】
  3. 港联证券“中特估值”重塑可转债市场
  4. STM32仿真模拟LED灯
  5. 电子摄像头可以取代镜子吗?
  6. SQL server删除数据库所有表数据
  7. 一、SASS(SCSS)
  8. PHP快递单号查询接口源码指导(快递鸟 API)
  9. 视盘检测 Accurate and Efficient Optic Disc Detection and Segmentation by a Circular Transformation
  10. wifi丢包率高怎么解决_几招解决无线路由器网速慢,断网丢包不稳定