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

程序报错RuntimeError: The size of tensor a (288) must match the size of tensor b (320) at non-singleton dimension 1 #3

Open
coldlarry opened this issue Aug 3, 2020 · 3 comments

Comments

@coldlarry
Copy link

old is Conv2d(32, 640, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False),new is Conv2d(32, 320, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)

Traceback (most recent call last): File "pruning.py", line 186, in
sketch_filter = sketch_matrix(m0.weight.data, l, dim=0,weight_norm_method='l2')
File "pruning.py", line 58, in sketch_matrix
sigmaSquare = sigmaSquareDiag - torch.eye(l) * torch.sum(theta)

当我想把原本640的卷积核剪枝为320个时,函数sketch_matrix会报如上错误,但其他地方是不会报错的。实在不知道,是因为程序漏洞报错,还是说因为这640个卷积核的确无法变为320个?

@lmbxmu
Copy link
Owner

lmbxmu commented Aug 3, 2020

old is Conv2d(32, 640, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False),new is Conv2d(32, 320, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)

Traceback (most recent call last): File "pruning.py", line 186, in
sketch_filter = sketch_matrix(m0.weight.data, l, dim=0,weight_norm_method='l2')
File "pruning.py", line 58, in sketch_matrix
sigmaSquare = sigmaSquareDiag - torch.eye(l) * torch.sum(theta)

当我想把原本640的卷积核剪枝为320个时,函数sketch_matrix会报如上错误,但其他地方是不会报错的。实在不知道,是因为程序漏洞报错,还是说因为这640个卷积核的确无法变为320个?

运行指令发来

@coldlarry
Copy link
Author

你好呀作者,我是把你的代码用在了其他非分类模型的剪枝上,使用时并没有修改你的sketch_martrix函数。 刚才说的那个问题,我感觉更有可能是程序无法从640个卷积核丢掉320个卷积核??? 因为当我把程序改为从640个卷积核,剪到剩下480个卷积核时,程序不会报错。 如果是剩下320个卷积,就会报错。 我还尝试随机生成一个张量,去使用sketch_martrix函数,如果剪的比例太大,也会出现这个问题。 想问一下,大佬是否有修改程序解决这种问题的好办法?

@lmbxmu
Copy link
Owner

lmbxmu commented Aug 3, 2020

你好呀作者,我是把你的代码用在了其他非分类模型的剪枝上,使用时并没有修改你的sketch_martrix函数。 刚才说的那个问题,我感觉更有可能是程序无法从640个卷积核丢掉320个卷积核??? 因为当我把程序改为从640个卷积核,剪到剩下480个卷积核时,程序不会报错。 如果是剩下320个卷积,就会报错。 我还尝试随机生成一个张量,去使用sketch_martrix函数,如果剪的比例太大,也会出现这个问题。 想问一下,大佬是否有修改程序解决这种问题的好办法?

linmb007 加我微信把错误截图发我看下

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