pytorch conv2d值无法转换为uint8_t类型而不溢出

2024-01-02

我正在传递一个torch.Tensor with a dtype of torch.uint8 to an nn.Conv2d模块,它给出了错误

运行时错误:值无法转换为 uint8_t 类型,无需 溢出:-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())

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

pytorch conv2d值无法转换为uint8_t类型而不溢出 的相关文章

随机推荐