Skip to content

Commit

Permalink
Add asserts to check for check for nonetypes, suggested by @alvinwan
Browse files Browse the repository at this point in the history
  • Loading branch information
greentfrapp committed Sep 29, 2020
1 parent 4a72bc5 commit a732f42
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lucent/optvis/render.py
Expand Up @@ -193,9 +193,13 @@ def hook_layers(net, prefix=[]):

def hook(layer):
if layer == "input":
return image_f()
if layer == "labels":
return list(features.values())[-1].features
return features[layer].features
out = image_f()
elif layer == "labels":
out = list(features.values())[-1].features
else:
assert layer in features, f"Invalid layer {layer}. Retrieve the list of layers with `lucent.modelzoo.util.get_model_layers(model)`."
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 README for example."
return out

return hook

1 comment on commit a732f42

@alvinwan
Copy link

Choose a reason for hiding this comment

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

@greentfrapp Thanks!

Please sign in to comment.