gpt4 book ai didi

python - pytorch conv2d 值不能在没有溢出的情况下转换为类型 uint8_t

转载 作者:行者123 更新时间:2023-12-04 12:13:31 25 4
gpt4 key购买 nike

我正在传递一个 torch.Tensordtypetorch.uint8nn.Conv2d模块,它给出了错误

RuntimeError: value cannot be converted to type uint8_t without overflow: -0.0344873



我的 conv2d 被定义为 self.conv1 = nn.Conv2d(3, 6, 5) .错误来自我的 forward当我将张量传递给模块时的方法,如 self.conv1(x) .张量的形状为 (4, 3, 480, 640)。我不知道如何解决这个问题。这是堆栈跟踪
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())

关于python - pytorch conv2d 值不能在没有溢出的情况下转换为类型 uint8_t,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60253449/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com