PyTorch 错误 RuntimeError: view size is not compatible with input tensor‘s size and stride (at least o

最新推荐文章于 2024-04-30 20:08:48 发布
最新推荐文章于 2024-04-30 20:08:48 发布 阅读量1.1w

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)

PyTorch 错误 RuntimeError: view size is not compatible with input tensor‘s size and stride (at least o 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 view size is not compatible with input tensor's size and stride (at least one dimension spans across two contiguous subspaces). Use .reshape(...) instead. 错误代码: prec1 = accuracy(-1 * dist_xt_ct.data, target_targets, topk=(1,))[0].item() 正确代码:
RuntimeError: view size is not compatible with input tensor‘s size and stride解决记录
File "/home/yuanlina/PycharmProjects/ViT-pytorch-main/test1-10.py", line 136, in Accuracy correct_k = correct[:k].view(-1).float().sum(0, keepdim=True) correct_k = correct[:k].contiguous().view(-1).float().sum(0, keepdim=True)
python运行报错: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. 感谢 柠檬树下你和我 的文章,知道了报错原因和解决方案。报错原因: view()需要Tensor中的元素地址是连续的,实际操作时可能出现Tensor不连续的
PyTorch - transforms.ColorJitter 改变图像的属性:亮度(brightness)、对比度(contrast)、饱和度(saturation)和色调(hue) 63204