lukemelas / PyTorch-Pretrained-ViT

Vision Transformer (ViT) in PyTorch
770 stars 124 forks source link

RuntimeError: view size is not compatible with input tensor's size and stride #26

Open aaliixii opened 2 years ago

aaliixii commented 2 years ago

Hi, When I try and run this with my own dataset with 4 classes, I get this error. Screenshot 2022-03-07 at 2 48 08 PM

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.

Any idea what could be causing this?

mohekouzhuxiangyu commented 2 years ago

hi, have you resolved this problem? i meet the same proble

AvisP commented 1 year ago

Hi,

I resolved it by changing the following line

https://github.com/lukemelas/PyTorch-Pretrained-ViT/blob/8ec2cab38b2dfae6386f37d4879a325f552eb791/examples/imagenet/main.py#L419

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