#!/usr/bin/env python # coding: utf-8 # # Lucid local development notebook # # This notebook allows you to use your development version of the lucid codebase. # It is meant to only be used during development of lucid, not when using it. # # Instead, see "usage_example.ipynb" in this folder for an example of how to use lucid in a notebook. # ## Setup # # ### Add local package to search path # In[1]: import os import sys module_path = os.path.abspath(os.path.join('..')) if module_path not in sys.path: sys.path.append(module_path) # Now we should be able to import it directly, just like if we installed it using `pip`: # # ```python # import lucid # ``` # # However, we will use `autoreload` so we can quickly iterate on local code changes: # # ### Enable autoreload # In[2]: get_ipython().run_line_magic('load_ext', 'autoreload') # In[3]: get_ipython().run_line_magic('aimport', 'lucid') get_ipython().run_line_magic('aimport', '-tensorflow') get_ipython().run_line_magic('aimport', '-numpy') # In[4]: get_ipython().run_line_magic('aimport', '') # Let's check that we're actually seeing the local version, not a package installed in site-packages. # Th next cell should show the path at which you cloned the lucid repo, not a system path: # In[5]: module_path = lucid.__path__[0] print("Lucid was loaded from {}.".format(module_path)) assert os.path.abspath("..") in module_path del module_path # ## Example usage # In[6]: import numpy as np # In[7]: image = np.random.normal(loc=.5, scale=.1, size=(200,200)) # In[15]: # this is how you set log levels globally: import logging logging.getLogger('lucid').setLevel(logging.DEBUG) # or per module: # logging.getLogger('lucid.misc.io').setLevel(logging.INFO) # In[16]: get_ipython().run_line_magic('autoreload', '') from lucid.misc.io import load, save, show image = load('../tests/fixtures/noise.png') print(image.dtype) show(image) # In[10]: get_ipython().run_line_magic('autoreload', '') array = load("../tests/fixtures/noise.png") print(array.dtype, array.shape) show(array, domain=None) array # In[11]: show(load("https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png")) # ## Optvis Usage # In[12]: from lucid.optvis import objectives, param, transform, render from lucid.modelzoo.vision_models import InceptionV1 # In[13]: model = InceptionV1() model.load_graphdef() # In[14]: _ = render.render_vis(model, "mixed3b_pre_relu:470", thresholds=(32, 256, 1024))