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

RuntimeError: view size is not compatible with input tensor‘s size and stride

程序员文章站 2022-06-15 13:50:11
...
  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)

correct_k = correct[:k].contiguous().view(-1).float().sum(0, keepdim=True)

添加.contiguous()即可

相关标签: pytorch