Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

view size is not compatible with input tensor's size and stride #259

Closed
bemoregt opened this issue Dec 23, 2020 · 1 comment
Closed

view size is not compatible with input tensor's size and stride #259

bemoregt opened this issue Dec 23, 2020 · 1 comment

Comments

@bemoregt
Copy link

Hi, @authman @vfdev-5 @consilium538 @ojdo @cove9988

I met this error when run main.py

python3 main.py data -a 'efficientnet-b4' --pretrained --batch-size 8
main.py:99: UserWarning: You have chosen a specific GPU. This will completely disable data parallelism.
warnings.warn('You have chosen a specific GPU. This will completely '
Use GPU: 1 for training
Loaded pretrained weights for efficientnet-b4
=> using pre-trained model 'efficientnet-b4'
Using image size 380
Traceback (most recent call last):
File "main.py", line 443, in
main()
File "main.py", line 117, in main
main_worker(args.gpu, ngpus_per_node, args)
File "main.py", line 265, in main_worker
train(train_loader, model, criterion, optimizer, epoch, args)
File "main.py", line 311, in train
acc1, acc5 = accuracy(output, target, topk=(1, 5))
File "main.py", line 437, in accuracy
correct_k = correct[:k].view(-1).float().sum(0, keepdim=True)
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.

What's wrong to me?

Thanks , in advance.
Best,

@bemoregt.

@lukemelas
Copy link
Owner

Hi, this is easy to fix: replace the instance of .view in the definition of the accuracy function with .replace

Also, for future reference, this is a PyTorch ImageNet code thing, not an EfficientNet thing

Hope this helps!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants