Skip to content

Add blur, gradient clipping, and regularization to ClassSpecificImageGenerator #72

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

Conversation

alexstoken
Copy link
Contributor

Thanks for a great visualization suite. I was having trouble getting a quality image from the class specific image generator so I implemented some of the techniques you suggested in the README and that are originally from Understanding Neural Networks Through Deep Visualization. These techniques greatly improved my visualizations.

Tested with torchvision 0.5.0 with model and image on cpu. To use GPU, will likely have to add logic to transfer image to cpu for PIL and then back to GPU for optimization, but I haven't looked in to this much.

@utkuozbulak
Copy link
Owner

Thanks for the PR @alexstoken! I'm currently on a very tight schedule due to some conference deadlines, I will try to have a look at these changes as soon as I can!

Copy link
Owner

@utkuozbulak utkuozbulak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be too much if I ask you to move the changes to a self-contained separate file (including the blurring without modifying misc_functions.py)? I would like to keep the bare-bone example as it is to allow people who recently started learning pytorch a gentle introduction.

@alexstoken
Copy link
Contributor Author

I'll make the adjustments in the next few days and I'll let you know when I push them. What would you like the new file and class called? Maybe something along the lines of RegularizedClassSpecificImageGenerator or AdvancedClassSpecificImageGenerator?

@utkuozbulak
Copy link
Owner

Both are fine by me. Can you just use snake case instead of camel? Also, please do include a header similar to what is below.

"""
Created on Mon Dec 31 99:99:99 2999
@author: Alex Stoken - https://github.com/alexstoken
"""

Create new file with regularized class specific image generator in it
@utkuozbulak
Copy link
Owner

Thanks for the changes! I will try to have a look at it as soon as I have free time at my hands!

@alexstoken
Copy link
Contributor Author

Thanks! Is it possible on your end to just accept the changes to the new file, or should I undo my commits to generate_class_specific_samples.py so that that can remain unchanged?

Preprocess function, which now contains blur and has been renamed preprocess_and_blur_image(), has been moved from misc_functios to this file
@utkuozbulak
Copy link
Owner

I would appreciate if you could undo changes on other two files, if you are too busy I can fix it as well.

Add cuda capabilities. Move model and processed_image to cuda, and final images to cpu, as required. This adds large speed improvements to the process.
PIL image verification left in
…te_class_specific_samples

Changes to file paths and an interation parameter remain
@alexstoken
Copy link
Contributor Author

I've now undone the regularization changes in the previous files, but I've left a few others for your consideration. The primary remaining changes in generate_class_specific_samples.py is an iterations argument (with default set as you had it) and changing the save folder to include the class label.

The primary change in misc_functions.py is checking if the input is a PIL image, and casting it to a PIL image if not. This is added because I found a case where a np.ndarray was passed to preprocess instead of a PIL.Image.

Finally, the new generate_regularized_class_samples.py is now cuda enabled, and runs must faster on the GPU devices. It auto detects if cuda is available and uses it if so.

Let me know what you think!

@utkuozbulak
Copy link
Owner

Hey @alexstoken, thanks for the changes. I will accept the PR and go over the changes the moment I have some free time.

@utkuozbulak utkuozbulak merged commit 1e7b098 into utkuozbulak:master Apr 8, 2020
@utkuozbulak
Copy link
Owner

Huh, finally able to merge the PR. Thanks a lot for it!

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

Successfully merging this pull request may close these issues.

2 participants