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

Backward anomaly problem #5

Open
ikourbane opened this issue Sep 7, 2020 · 5 comments
Open

Backward anomaly problem #5

ikourbane opened this issue Sep 7, 2020 · 5 comments

Comments

@ikourbane
Copy link

Thank you very much for your work, I found an anomaly when I try to differentiate it and do the backward step, your Net has many in-place operations which makes it impossible to calculate the gradients. If anyone encounters the same problem replace the first few lines in the forward function to:

    def forward(self, img):

        blurred_img_r = self.gaussian_filter_vertical(self.gaussian_filter_horizontal(img[:, 0:1]))
        blurred_img_g = self.gaussian_filter_vertical(self.gaussian_filter_horizontal(img[:, 1:2]))
        blurred_img_b = self.gaussian_filter_vertical(self.gaussian_filter_horizontal(img[:, 2:3]))

        grad_x_r = self.sobel_filter_horizontal(blurred_img_r)
        grad_y_r = self.sobel_filter_vertical(blurred_img_r)
        grad_x_g = self.sobel_filter_horizontal(blurred_img_g)
        grad_y_g = self.sobel_filter_vertical(blurred_img_g)
        grad_x_b = self.sobel_filter_horizontal(blurred_img_b)
        grad_y_b = self.sobel_filter_vertical(blurred_img_b)
@ikourbane
Copy link
Author

I just fixed the inplace operations.

@anjaeju
Copy link

anjaeju commented Mar 24, 2021

Thanks you for Issues ikourbane.

I also encounter this issues here.
Even though, i changed the code you write above, the backward gradient doesn't flow.
could you give me some more details?

@anjaeju
Copy link

anjaeju commented Mar 25, 2021

Thanks you for Issues ikourbane.

I also encounter this issues here.
Even though, i changed the code you write above, the backward gradient doesn't flow.
could you give me some more details?

Fixed. I also changed all inplace operations. U should change the all inplace operation in code lines including the above codes.

@XGBoost
Copy link

XGBoost commented Jul 22, 2021

@anjaeju could you please provide the corresponding modified code? Thank you very much!

@jungeun122333
Copy link

I also modified grad_mag and other things according to @anjaeju !

before:

grad_mag = torch.sqrt(grad_x_r**2 + grad_y_r**2) 
grad_mag += torch.sqrt(grad_x_g**2 + grad_y_g**2) 
grad_mag += torch.sqrt(grad_x_b**2 + grad_y_b**2)
        

after:

grad_mag = torch.sqrt(grad_x_r**2 + grad_y_r**2) + torch.sqrt(grad_x_g**2 + grad_y_g**2) + torch.sqrt(grad_x_b**2 + grad_y_b**2)
        

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

4 participants