out1 = torch.max(out1, 1) # (batch, embedding_size)
out1 = self.linear(out1) # (batch, linear_hidden_size)

抛出错误

  File "/diske/Anaconda3/envs/pytorch1.4/lib/python3.7/site-packages/torch/nn/modules/module.py", line 722, in _call_implresult = self.forward(*input, **kwargs)File "lstm.py", line 75, in forwardout1 = self.linear(out1) # (batch, linear_hidden_size)File "/diske/Anaconda3/envs/pytorch1.4/lib/python3.7/site-packages/torch/nn/modules/module.py", line 722, in _call_implresult = self.forward(*input, **kwargs)File "/diske/Anaconda3/envs/pytorch1.4/lib/python3.7/site-packages/torch/nn/modules/linear.py", line 91, in forwardreturn F.linear(input, self.weight, self.bias)File "/diske/Anaconda3/envs/pytorch1.4/lib/python3.7/site-packages/torch/nn/functional.py", line 1672, in linearif input.dim() == 2 and bias is not None:
AttributeError: 'torch.return_types.max' object has no attribute 'dim'

发现官网对torch.max()的解释是这样:

torch.max 返回值是一个tuple,第一个元素是max值,第二个元素是max值的索引。

>>> a = torch.randn(4, 4)
>>> a
tensor([[-1.2360, -0.2942, -0.1222,  0.8475],[ 1.1949, -1.1127, -2.2379, -0.6702],[ 1.5717, -0.9207,  0.1297, -1.8768],[-0.6172,  1.0036, -0.6060, -0.2432]])
>>> torch.max(a, 1)
torch.return_types.max(values=tensor([0.8475, 1.1949, 1.5717, 1.0036]), indices=tensor([3, 0, 0, 1]))

只需要获得最大值即可

out1 = torch.max(out1, 1) # (batch, embedding_size)
out1 = self.linear(out1.values) # (batch, linear_hidden_size)
# 或者
val, ind = torch.max(out1, 1) # (batch, embedding_size)
out1 = self.linear(val) # (batch, linear_hidden_size)

AttributeError: ‘torch.return_types.max‘ object has no attribute ‘dim‘相关推荐

  1. AttributeError: 'PyQt5.QtCore.pyqtSignal' object has no attribute 'connect'

    AttributeError: 'PyQt5.QtCore.pyqtSignal' object has no attribute 'connect' https://blog.csdn.net/je ...

  2. M1Mac使用TensorFlow出现AttributeError: ‘h5py.h5t.TypeID‘ object has no attribute ‘set_fields‘的解决办法

    问题 TensorFlow使用Apple官方优化版2.4.1(conda-forge),使用tf.keras后端时候出现: AttributeError: 'h5py.h5t.TypeID' obje ...

  3. AttributeError: ‘tensorrt.tensorrt.Builder‘ object has no attribute ‘max_workspace_size‘

    TensorRT版本:8.4 从网上下载的代码,运行报错,如上述标题. 1.错误:AttributeError: 'tensorrt.tensorrt.Builder' object has no a ...

  4. AttributeError: ‘list’ object has no attribute “dim”

    这错是因为居然自己蠢到在pytorch用list当tensor用 将get_image转成tensor即可 get_image=torch.from_numpy(numpy.array(get_ima ...

  5. 问题:AttributeError: 'Tensor' object has no attribute 'creator'

    AttributeError: 'Tensor' object has no attribute 'creator' 根据pytorch官方文档的说法,变量具有如上的三个属性,在获取y操作的creat ...

  6. AttributeError: ‘str‘ object has no attribute ‘copy

    在加载模型时出现 AttributeError: 'str' object has no attribute 'copy' 错误 解决方案: 将 model.load_state_dict(state ...

  7. pytorch版本问题:AttributeError: 'module' object has no attribute '_rebuild_tensor_v2'

    用pytorch加载训练好的模型的时候遇到了如下的问题: AttributeError: 'module' object has no attribute '_rebuild_tensor_v2' 到 ...

  8. AttributeError: ‘Embeddings‘ object has no attribute ‘d_model‘

    求助AttributeError: 'Embeddings' object has no attribute 'd_model' embedding.d_model不是transformer_util ...

  9. 使用torchsummary时出现AttributeError: ‘list‘ object has no attribute ‘size‘解决方案

    目录 1 问题 2 原因 3 解决方案 4 代码 1 问题 使用torchsummary查看网络结构时报错:AttributeError: 'list' object has no attribute ...

  10. Jetson Nano【13】关于torch2trt报错:AttributeError: ‘Tensor‘ object has no attribute ‘_trt‘的一种可能性

    尝试转换,报错,日志如下 AttributeError Traceback (most recent call last) <ipython-input-24-0cf9bfd4fe52> ...

最新文章

  1. 平衡自动化与智能化,构建AI生态系统
  2. php ci框架分页类,nusoap 与 CI框架不用WSDL
  3. golang中的web服务平滑重启
  4. matlab中的方波信号图片_电气信息类专业课程之matlab系统仿真 第十章 DBPSK调制解调器(9)...
  5. 成功解决explicit device specific/device:GPU:0' because no supported kernel for GPU devices is available.
  6. 开放中国农业-国际农民丰收节贸易会:谋定全球共同发展
  7. WebBrowser控件跨域访问页面内容
  8. C++经典面试题(最全,面中率最高)
  9. Sublime介绍安装和使用(转载)
  10. python3.7和2.7_为两个python版本(2.7和3.7)Windows 10安装pip
  11. js 匿名函数_编写高质量箭头函数的5个最佳做法
  12. 软考论文写作的时间分配
  13. 科研网站大全,你值得拥有!
  14. matlab二叉树期权定价,二叉树期权定价模型
  15. Android 腾讯地图 选点定位,仿微信发送位置
  16. 【计算机毕业设计】学生宿舍管理系统
  17. C语言循环输出能被3整除的数
  18. 科学家研发独特AI算法:用WiFi监测你是否在做梦
  19. 电磁兼容试验项目之谐波电流试验
  20. 软件测试需求标准 国标,国家标准 GBT 15532-2008 计算机软件测试规范(60页)-原创力文档...

热门文章

  1. Java多线程(六)线程池
  2. virtualbox下宿主机与虚拟机互通
  3. 让人死去活来的cocos2d-x安卓开发环境搭建(windows+eclipse+ndk 不用cygwin)【上图】
  4. UVALive 5760 Alice and Bob
  5. bzoj 5281: [Usaco2018 Open]Talent Show【dp】
  6. 使用JavaFX打开fxml,找不到打开的图形界面
  7. IE, FF, Safari前端开发常用调试工具(转载)
  8. ExtJs xtype一览(转存)
  9. 移动开发框架,第【三】弹:Zepto.js
  10. net4.0的从客户端中检测到有潜伏危险的 Request.Form