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

Unified, centralized and simplified code; added CPU option #6

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

mbuet2ner
Copy link

@mbuet2ner mbuet2ner commented Sep 21, 2019

Here are some things I added/ changed:

  • dedicated filtervisualizer.py file
  • dedicated plot_reconstructions.py file
  • easier accessible due to streamlined functions. Easier to use other neural nets, without changing too much code.
  • added CPU option
  • removed unused imports, codes, parameters
  • don't overwrite built in filter function
  • pep8 guidelines
  • f strings where applicable
  • removed imgur code (I am not sure if it is really necessary for the task)

Things I have not changed yet, but will do in the future:

  • vgg16 and resnet34 part 2 notebooks

Thus, it should be much easier to change things in the future/ migrate to new fastai version.

notebooks do not have their own implementation of the code but rely on the centralized files
@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

You'll be able to see Jupyter notebook diff and discuss changes. Powered by ReviewNB.

@mbuet2ner
Copy link
Author

@fg91 sorry for the mess. I know it is hard to review, because it combines quite a lot of changes in one PR. Should I make several pull requests out of it?

opt_steps_ = int(opt_steps * 1.3)
else:
opt_steps_ = opt_steps
train_tfms, val_tfms = tfms_from_model(self.model, sz)
Copy link
Owner

Choose a reason for hiding this comment

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

This is done in the get_transformed and most_activated methods as well. How about making these instance attributes?

Copy link
Author

Choose a reason for hiding this comment

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

Oh you are right. I overlooked that I'm afraid. I will change that!

Copy link
Owner

Choose a reason for hiding this comment

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

Thanks!

@fg91
Copy link
Owner

fg91 commented Sep 27, 2019

Hey,
sorry it took me so long to react. First of all, thank you for taking the time to improve this tutorial!

Would you be willing to change the following?

  • The experiments folder contains additional notebooks provided by a reader of the blog post, so I would like to keep the FilterVisualizer separated from it. Could you please move the filtervisualizer.py out of the experiments folder? The plot_reconstructions.py can stay in the experiments folder as it is only used for the additional experiments...
  • Would you be willing to simplify the Calculate_mean_activation_per_filter_in_specific_layer_given_an_image.ipynb using the most_activated method from FiterVisualizer?

Thanks!

Fabio

activations = SaveFeatures(layer) # register hook
self.model(V(transformed)[None])

print(activations.features[0, 5].mean().data.cpu().numpy())
Copy link
Owner

Choose a reason for hiding this comment

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

Why print especially activations.features[0, 5]? This was from the experiments folder, correct? :)

Copy link
Author

Choose a reason for hiding this comment

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

Yep. Sorry for that. I will also change that!

Copy link
Owner

Choose a reason for hiding this comment

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

No need to apologize, I'm happy you put effort into improving the code, thanks for that!

Copy link
Author

Choose a reason for hiding this comment

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

The experiments folder contains additional notebooks provided by a reader of the blog post, so I would like to keep the FilterVisualizer separated from it. Could you please move the filtervisualizer.py out of the experiments folder? The plot_reconstructions.py can stay in the experiments folder as it is only used for the additional experiments...

I will move it to the root then!

Would you be willing to simplify the Calculate_mean_activation_per_filter_in_specific_layer_given_an_image.ipynb using the most_activated method? from FiterVisualizer`?

Yes! I was thinking thinking about it already but decided not to, because

  1. the notebook would be basically empty then (perhaps I can combine the two then?) and
  2. I was not sure whether to include the threshold in the method or not.
    IMHO it makes more sense to do the threshold outside of the method.

What do you think?

Copy link
Owner

Choose a reason for hiding this comment

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

  • Yes, I agree to not include the threshold in the method.
  • I would prefer to keep two separate notebooks even though there is not that much in the second one because I would have to go through the blog post and remove any hyperlinks to the 2nd notebook ahah

Copy link
Author

Choose a reason for hiding this comment

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

Okay, that does make sense! I will apply the discussed changes and keep both notebooks separated then! 😃

adds parent dir to sys.path
prior to that it used its own implementation
@mbuet2ner
Copy link
Author

mbuet2ner commented Oct 12, 2019

I finally addressed your proposed changes 🎉 :

  • filtervisualizer.py is now in root. See 12ebf75
  • Calculate_mean_activation_per_filter_in_specific_layer_given_an_image.ipynb now uses filtervisualizer.py. See 9b4b794
  • train_tfms and val_tfms are now instance attributes. See 84ea7cb
  • FilterVisualizer.most_activated() method does not print any mean_act at all (I do not think it is necessary?). Especially no activations.features[0, 5] 😁 . See 9b4b794

@mbuet2ner
Copy link
Author

@fg91 If there is anything else you want me to change, just let me know.

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