欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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)

相关标签: 深度学习