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

Hi,after I replace the code ,please help #12

Open
gden138 opened this issue Apr 25, 2019 · 2 comments
Open

Hi,after I replace the code ,please help #12

gden138 opened this issue Apr 25, 2019 · 2 comments

Comments

@gden138
Copy link

gden138 commented Apr 25, 2019

Hi,
It is the problem of tensor dimension.
Just replace the code
norm_weight = self.weight * (weight_scale[None,:,None,None] / torch.sqrt((self.weight ** 2).sum(3).sum(2).sum(0) + 1e-6)).expand_as(self.weight)
with
norm_weight = self.weight * (weight_scale[None,:,None,None] / torch.sqrt((self.weight ** 2).sum(3).sum(2).sum(0) + 1e-6).reshape([-1, 1, 1, 1])).expand_as(self.weight)

Originally posted by @zcwang0702 in #6 (comment)

but after I replace the code
new error:
RuntimeError: The expanded size of the tensor (128) must match the existing size (3) at non-singleton dimension 0

original code error :
File "/home/gis/PycharmProjects/guo/ssl_bad_gan-master/model.py", line 165, in forward
norm_weight = self.weight * (weight_scale[None,:,None,None] / torch.sqrt((self.weight ** 2).sum(3).sum(2).sum(0) + 1e-6)).expand_as(self.weight)
RuntimeError: The expanded size of the tensor (5) must match the existing size (3) at non-singleton dimension 3
Thank you!

@xuyujie2
Copy link

Hi,
It is the problem of tensor dimension.
Just replace the code
norm_weight = self.weight * (weight_scale[None,:,None,None] / torch.sqrt((self.weight ** 2).sum(3).sum(2).sum(0) + 1e-6)).expand_as(self.weight)
with
norm_weight = self.weight * (weight_scale[None,:,None,None] / torch.sqrt((self.weight ** 2).sum(3).sum(2).sum(0) + 1e-6).reshape([-1, 1, 1, 1])).expand_as(self.weight)

Originally posted by @zcwang0702 in #6 (comment)

but after I replace the code
new error:
RuntimeError: The expanded size of the tensor (128) must match the existing size (3) at non-singleton dimension 0

original code error :
File "/home/gis/PycharmProjects/guo/ssl_bad_gan-master/model.py", line 165, in forward
norm_weight = self.weight * (weight_scale[None,:,None,None] / torch.sqrt((self.weight ** 2).sum(3).sum(2).sum(0) + 1e-6)).expand_as(self.weight)
RuntimeError: The expanded size of the tensor (5) must match the existing size (3) at non-singleton dimension 3
Thank you!
try
norm_weight = self.weight * (weight_scale[None,:,None,None] / torch.sqrt((self.weight ** 2).sum(3).sum(2).sum(0) + 1e-6).reshape([1, -1, 1, 1])).expand_as(self.weight)

@gden138
Copy link
Author

gden138 commented Apr 25, 2019 via email

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