pytorch-pruning icon indicating copy to clipboard operation
pytorch-pruning copied to clipboard

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

Open howtocodewang opened this issue 6 years ago • 4 comments

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!

howtocodewang avatar Oct 30 '18 14:10 howtocodewang

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

wuzhiyang2016 avatar Nov 20 '18 07:11 wuzhiyang2016

@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!

ghost avatar Nov 28 '18 23:11 ghost

@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)"

wuzhiyang2016 avatar Dec 04 '18 02:12 wuzhiyang2016

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

ygean avatar Dec 31 '18 08:12 ygean