小编Yun*_*Liu的帖子

Pytorch:运行时错误:预期的 dtype Float 但得到了 dtype Long

在 Pytorch 中构建简单的神经网络时,我遇到了这个奇怪的错误。我不明白这个错误以及为什么在向后函数中考虑 Long 和 Float 数据类型。有没有人遇到过这种情况?谢谢你的帮助。

Traceback (most recent call last):
  File "test.py", line 30, in <module>
    loss.backward()
  File "/home/liuyun/anaconda3/envs/torch/lib/python3.7/site-packages/torch/tensor.py", line 198, in backward
    torch.autograd.backward(self, gradient, retain_graph, create_graph)
  File "/home/liuyun/anaconda3/envs/torch/lib/python3.7/site-packages/torch/autograd/__init__.py", line 100, in backward
    allow_unreachable=True)  # allow_unreachable flag
RuntimeError: expected dtype Float but got dtype Long (validate_dtype at /opt/conda/conda-bld/pytorch_1587428398394/work/aten/src/ATen/native/TensorIterator.cpp:143)
frame #0: c10::Error::Error(c10::SourceLocation, std::string const&) + 0x4e (0x7f5856661b5e in /home/liuyun/anaconda3/envs/torch/lib/python3.7/site-packages/torch/lib/libc10.so)
frame #1: at::TensorIterator::compute_types() + 0xce3 (0x7f587e3dc793 in /home/liuyun/anaconda3/envs/torch/lib/python3.7/site
-packages/torch/lib/libtorch_cpu.so)
frame #2: at::TensorIterator::build() + 0x44 (0x7f587e3df174 in /home/liuyun/anaconda3/envs/torch/lib/python3.7/site-packages
/torch/lib/libtorch_cpu.so)
frame #3: …
Run Code Online (Sandbox Code Playgroud)

python backpropagation deep-learning pytorch

5
推荐指数
1
解决办法
8327
查看次数

标签 统计

backpropagation ×1

deep-learning ×1

python ×1

pytorch ×1