If you want to study techniques for visualizing and understanding neural networks, it's important to be able to try your experiments on multiple models.
Lucid is a library for visualizing neural networks. As of lucid v0.3, we provide a consistent API for interacting with 27 different vision models.
In [0]:
# Expanded modelzoo is only available as of lucid v0.3
!pip install --quiet lucid==0.3
#tensorflow_version only works in colab
%tensorflow_version 1.x
import numpy as np
import tensorflow as tf
assert tf.__version__.startswith('1')
from lucid.misc.io import show, load
import lucid.optvis.objectives as objectives
import lucid.optvis.param as param
import lucid.optvis.render as render
import lucid.optvis.transform as transform
In [0]:
# Lucid's modelzoo can be accessed as classes in vision_models
import lucid.modelzoo.vision_models as models
# ... or throguh a more systematic factory API
import lucid.modelzoo.nets_factory as nets
In [3]:
print ""
print "Model".ljust(27), " ", "Dataset"
print ""
for name, Model in nets.models_map.iteritems():
print name.ljust(27), " ", Model.dataset
In [4]:
models.InceptionV4_slim.layers
Out[4]:
In [5]:
model = models.InceptionV4_slim()
model.load_graphdef()
model.show_graph()
In [9]:
model = models.InceptionV4_slim()
model.load_graphdef()
_ = render.render_vis(model, "InceptionV4/InceptionV4/Mixed_6b/concat:0")
In [8]:
from lucid.recipes.caricature import feature_inversion
img = load("https://storage.googleapis.com/lucid-static/building-blocks/examples/dog_cat.png")
model = models.InceptionV4_slim()
model.load_graphdef()
result = feature_inversion(img, model, "InceptionV4/InceptionV4/Mixed_6b/concat", n_steps=512, cossim_pow=0.0)
show(result)