pytorch conv2d value cannot be converted to type uint8_t without overflow(pytorch conv2d 值无法在不溢出的情况下转换为类型 uint8_t)
问题描述
我将带有 dtype 的 torch.uint8 的 torch.Tensor 传递给 nn.Conv2d> 模块,它给出了错误
I'm passing a torch.Tensor with a dtype of torch.uint8 to an nn.Conv2d module and it is giving the error
RuntimeError: 值不能被转换为类型 uint8_t溢出:-0.0344873
RuntimeError: value cannot be converted to type uint8_t without overflow: -0.0344873
我的 conv2d 定义为 self.conv1 = nn.Conv2d(3, 6, 5).当我将张量传递给像 self.conv1(x) 这样的模块时,错误出现在我的 forward 方法中.张量的形状为 (4, 3, 480, 640).我不知道如何解决这个问题.这是堆栈跟踪
My conv2d is defined as self.conv1 = nn.Conv2d(3, 6, 5). The error comes in my forward method when I pass the tensor to the module like self.conv1(x). The tensor has shape (4, 3, 480, 640). I'm not sure how to fix this. Here is the stack trace
Traceback (most recent call last):
File "cnn.py", line 54, in <module>
outputs = net(inputs)
File "/Users/my_repos/venv_projc/lib/python3.7/site-packages/torch/nn/modules/module.py", line 532, in __call__
result = self.forward(*input, **kwargs)
File "cnn.py", line 24, in forward
test = self.conv1(x)
File "/Users/my_repos/venv_projc/lib/python3.7/site-packages/torch/nn/modules/module.py", line 532, in __call__
result = self.forward(*input, **kwargs)
File "/Users/my_repos/venv_projc/lib/python3.7/site-packages/torch/nn/modules/conv.py", line 345, in forward
return self.conv2d_forward(input, self.weight)
File "/Users/my_repos/venv_projc/lib/python3.7/site-packages/torch/nn/modules/conv.py", line 342, in conv2d_forward
self.padding, self.dilation, self.groups)
RuntimeError: value cannot be converted to type uint8_t without overflow: -0.0344873
推荐答案
将张量转换为浮点数似乎可以解决它self.conv1(x.float())
Converting the tensor to a float seemed to fix it self.conv1(x.float())
这篇关于pytorch conv2d 值无法在不溢出的情况下转换为类型 uint8_t的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:pytorch conv2d 值无法在不溢出的情况下转换为类型
基础教程推荐
- Discord.py 缺少必需的参数 2022-01-01
- 由Python将MP3转换为MIDI(类型错误:无法加载插件:mtg-Melodia:Melodia) 2022-01-01
- 使用生成器和迭代器时 Python 多循环失败 2022-01-01
- pyserial - 可以从线程 a 写入串行端口,是否阻塞从线程 b 读取? 2022-01-01
- 与常规 dict 相比,Python manager.dict() 非常慢 2022-01-01
- 尝试制作WhatsApp机器人 2022-01-01
- numpy float:比算术运算中内置的慢 10 倍? 2022-01-01
- 将 x 轴刻度更改为自定义字符串 2022-01-01
- 在 Celery 工作人员中捕获 Heroku SIGTERM 以优雅地关 2022-01-01
- 用 Python 编写 Fortran 无格式文件 2022-01-01
