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

Suggestion for lucent.optvis.render.hook_model #11

Closed
alvinwan opened this issue Sep 24, 2020 · 2 comments
Closed

Suggestion for lucent.optvis.render.hook_model #11

alvinwan opened this issue Sep 24, 2020 · 2 comments

Comments

@alvinwan
Copy link

alvinwan commented Sep 24, 2020

First, thanks for making this. Lifesaver. Two thoughts (Fwiw, the nested functions, higher-order functions and decorators make things a biiiiit hard to follow when debugging):

  1. I initially dun goofed and didn't eval the model (even though the very example notebook I'm using from lucent does lol). Maybe the hook_model function could check for nonetypes and tell the user to eval, if no saved feature maps are found?
  2. PyTorch module names usually use dot notation. Maybe use dots instead of underscores? Or just tell the user which feature map names are available and the user'll figure it out quickly enough

Suggested replacement for this function:

def hook(layer):

def hook(layer):
        if layer == "input":
            out = image_f()
        elif layer == "labels":
            out = list(features.values())[-1].features
        else:
            assert layer in features, f"Invalid layer {layer}. Pick from one of {features.keys()}"  # suggestion 2 ish
            out = features[layer].features
        assert out is not None, "There are no saved feature maps. Make sure to put the model in eval mode, like so: `model.to(device).eval()`. See Lucent notebook for example."   # suggestion 1, tell user to eval
        return out

*I ran it on resnet18. Gorgeous and worked out of the box btw.

download-4
download-5
download-6
download-7

@greentfrapp
Copy link
Owner

Hey @alvinwan I'm glad to know that this helped! Thanks for the suggestions too! Good point and makes a lot of sense, I'll work them in

@alvinwan
Copy link
Author

a732f42

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