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

Python 3.6, pytorch 0.4.1, getting RuntimeError: Dimension out of range (expected to be in range of [-2, 1], but got 3) #25

Open
howtocodewang opened this issue Oct 30, 2018 · 4 comments

Comments

@howtocodewang
Copy link

howtocodewang commented Oct 30, 2018

My running environment is:

  • Ubuntu 16.04LTS

  • pytorch 0.4.1

  • python 3.6

I got a problem is:
`/home/wangshuo/anaconda3/envs/pytorch/lib/python3.6/site-packages/torchvision-0.2.1-py3.6.egg/torchvision/transforms/transforms.py:188: UserWarning: The use of the transforms.Scale transform is deprecated, please use transforms.Resize instead.
/home/wangshuo/anaconda3/envs/pytorch/lib/python3.6/site-packages/torchvision-0.2.1-py3.6.egg/torchvision/transforms/transforms.py:563: UserWarning: The use of the transforms.RandomSizedCrop transform is deprecated, please use transforms.RandomResizedCrop instead.
Accuracy : 1.0
Number of prunning iterations to reduce 67% filters 5
Ranking filters..
Traceback (most recent call last):
File "finetune.py", line 270, in
fine_tuner.prune()
File "finetune.py", line 217, in prune
prune_targets = self.get_candidates_to_prune(num_filters_to_prune_per_iteration)
File "finetune.py", line 184, in get_candidates_to_prune
self.train_epoch(rank_filters = True)
File "finetune.py", line 179, in train_epoch
self.train_batch(optimizer, batch.cuda(), label.cuda(), rank_filters)
File "finetune.py", line 172, in train_batch
self.criterion(output, Variable(label)).backward()
File "/home/wangshuo/anaconda3/envs/pytorch/lib/python3.6/site-packages/torch/tensor.py", line 93, in backward
torch.autograd.backward(self, gradient, retain_graph, create_graph)
File "/home/wangshuo/anaconda3/envs/pytorch/lib/python3.6/site-packages/torch/autograd/init.py", line 90, in backward
allow_unreachable=True) # allow_unreachable flag
File "finetune.py", line 77, in compute_rank
sum(dim=2).sum(dim=3)[0, :, 0, 0].data

RuntimeError: Dimension out of range (expected to be in range of [-2, 1], but got 3)
`
I have tried the solution given in https://github.com/jacobgil/pytorch-pruning/issues/6#issuecomment-332757962. This problem still exists.

Can anyone help me solve it?

Thanks!

@wuzhiyang2016
Copy link

pytorch version caused the problem, you can change to this: values =
torch.sum((activation * grad), dim=0, keepdim = True).
sum(dim=2, keepdim = True).sum(dim=3,keepdim = True)[0, :, 0, 0].data

@ghost
Copy link

ghost commented Nov 28, 2018

@wuzhiyang2016 I used keepdim=True, but I still get errors at the same point.

RuntimeError: The size of tensor a (14) must match the size of tensor b (28) at non-singleton dimension 3
Any idea?

Thanks!

@wuzhiyang2016
Copy link

@wuzhiyang2016 I used keepdim=True, but I still get errors at the same point.

RuntimeError: The size of tensor a (14) must match the size of tensor b (28) at non-singleton dimension 3
Any idea?

Thanks!

what's your pytorch version? and your error is not "Dimension out of range (expected to be in range of [-2, 1], but got 3)"

@ygean
Copy link

ygean commented Dec 31, 2018

@bidakos Have you solved this problem? I need your help and I met same issue, pls help me

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

3 participants