PyTorch 错误 RuntimeError: view size is not compatible with input tensor‘s size and stride (at least o
程序员文章站
2022-06-15 13:54:35
...
PyTorch 错误 RuntimeError: view size is not compatible with input tensor’s size and stride (at least one dimension spans across two contiguous subspaces). Use .reshape(…) instead.
flyfish
具体提示如下
Processinggender.py:212: UserWarning: This overload of cuda is deprecated:
cuda(torch.device device, bool async, *, torch.memory_format memory_format)
Consider using one of the following signatures instead:
cuda(torch.device device, bool non_blocking, *, torch.memory_format memory_format) (Triggered internally at /pytorch/torch/csrc/utils/python_arg_parser.cpp:882.)
inputs, targets = inputs.cuda(), targets.cuda(async=True)
Traceback (most recent call last):
correct_k = correct[:k].view(-1)
RuntimeError: view size is not compatible with input tensor's size and stride (at least one dimension spans across two contiguous subspaces). Use .reshape(...) instead.
解决方案
按照提示
correct_k = correct[:k].view(-1)
更改为
correct_k = correct[:k].contiguous().view(-1)
上一篇: Linux系统部署网站
推荐阅读
-
RuntimeError: view size is not compatible with input tensor‘s size and stride
-
PyTorch 错误 RuntimeError: view size is not compatible with input tensor‘s size and stride (at least o
-
RuntimeError: view size is not compatible with input tensor‘s size and stride
-
RuntimeError: view size is not compatible with input tensor‘s size and stride解决记录