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

Pruned error #2

Open
LXWDL opened this issue Mar 20, 2018 · 7 comments
Open

Pruned error #2

LXWDL opened this issue Mar 20, 2018 · 7 comments

Comments

@LXWDL
Copy link

LXWDL commented Mar 20, 2018

Thank you for sharing, I encountered the following error in the implementation of the following code,
python prune.py --model model_best.pth.tar --save pruned.pth.tar --percent 0.7
error:
Traceback (most recent call last):
File "prune.py", line 120, in
m1.weight.data = m0.weight.data[idx1].clone()
TypeError: indexing a tensor with an object of type numpy.ndarray. The only supported types are integers, slices, numpy scalars and torch.cuda.LongTensor or torch.cuda.ByteTensor as the only argument.
I am not very familiar with Pytorch, do not know how to solve, can you help me fix this bug? Thanks for your help, I use Python 2.7.14, Pytorch 0.20

@angelamin
Copy link

I meet the same error, have you solved it? thanks for your reply

@LXWDL
Copy link
Author

LXWDL commented Mar 20, 2018

Not yet, the following error occurred when I used the version of Pytorch 0.1.12:
Traceback (most recent call last):
File "prune.py", line 47, in
Total = m.weight.data.shape[0]
AttributeError: 'torch.cuda.FloatTensor' object has no attribute 'shape'

@Coderx7
Copy link

Coderx7 commented Jun 30, 2018

@angelamin ,@LXWDL: Did you solve this issue? I'm facing the very same error. I'm on pytorch 0.3.1

@struggle5101
Copy link

@LXWDL @angelamin
I meet the same error, and I change it to:
thre=thre.to('cuda:0')
mask = weight_copy.abs().gt(thre).float()
and it is solved.

@naranglovish
Copy link

@LXWDL @struggle5101 @Coderx7 @angelamin
I am getting this error

File "prune.py", line 131, in
w = m0.weight.data[:, idx0, :, :].clone()
IndexError: When performing advanced indexing the indexing objects must be LongTensors or convertible to LongTensors

Can anybody help??

@Coderx7
Copy link

Coderx7 commented Sep 1, 2018

@naranglovish : Use this port instead.

@chuliuT
Copy link

chuliuT commented Mar 27, 2020

@LXWDL @struggle5101 @Coderx7 @angelamin
I am getting this error

File "prune.py", line 131, in
w = m0.weight.data[:, idx0, :, :].clone()
IndexError: When performing advanced indexing the indexing objects must be LongTensors or convertible to LongTensors

Can anybody help??

i met the same Q
In this link :slim
replace code under below,it should be works
elif isinstance(m0, nn.Conv2d):
idx0 = np.squeeze(np.argwhere(np.asarray(start_mask.cpu().numpy())))
idx1 = np.squeeze(np.argwhere(np.asarray(end_mask.cpu().numpy())))
print('In shape: {:d}, Out shape {:d}.'.format(idx0.size, idx1.size))
if idx0.size == 1:
idx0 = np.resize(idx0, (1,))
if idx1.size == 1:
idx1 = np.resize(idx1, (1,))
w1 = m0.weight.data[:, idx0.tolist(), :, :].clone()
w1 = w1[idx1.tolist(), :, :, :].clone()
m1.weight.data = w1.clone()

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

6 participants