<jupyter_start><jupyter_text>Feature Visualization- This notebook does basic feature visualization of <NAME> DLA CNN Model  Install imports, define and load model<jupyter_code># Imports

import numpy as np
import tensorflow as tf
import scipy.ndimage as nd
import time
import imageio

import matplotlib
import matplotlib.pyplot as plt

import lucid.modelzoo.vision_models as models
from lucid.misc.io import show
import lucid.optvis.objectives as objectives
import lucid.optvis.param as param
import lucid.optvis.render as render
import lucid.optvis.transform as transform

from lucid.optvis.objectives import wrap_objective, _dot, _dot_cossim
from lucid.optvis.transform import standard_transforms, crop_or_pad_to, pad, jitter, random_scale, random_rotate
from lucid.modelzoo.vision_base import Model

class DLA(Model):
    model_path = '../protobufs/full_model_8_13.pb'
    image_shape = [1, 400]
    image_value_range = [0, 1]
    input_name = 'x'
model = DLA()
model.load_graphdef()
LAYERS = { 'conv1': ['Conv2D', 100],
           'conv1_relu': ['Relu', 100],
           'pool1': ['MaxPool', 100],
           'conv2': ['Conv2D_1', 96],
           'conv2_relu': ['Relu_1', 96],
           'pool2': ['MaxPool_1', 96],
           'conv3': ['Conv2D_2', 96],
           'conv3_relu': ['Relu_2', 96],
           'pool3': ['MaxPool_2', 96]}<jupyter_output><empty_output><jupyter_text>Simple 3D Visualizations of a neuron- Create 3D visualizations<jupyter_code># Specify param.image size to work with our models input, must be a multiple of 400.
param_f = lambda: param.image(120, h=120, channels=3)

# std_transforms = [
#     pad(2, mode="constant", constant_value=.5),
#     jitter(2)]
# transforms = std_transforms + [crop_or_pad_to(*model.image_shape[:2])]
transforms = []

# Specify the objective

# neuron = lambda n: objectives.neuron(LAYERS['pool1'][0], n)
# obj = neuron(0)
channel = lambda n: objectives.channel(LAYERS['pool1'][0], n)
obj = channel(0)

# Specify the number of optimzation steps, will output image at each step
thresholds = (1, 2, 4, 8, 16, 32, 64, 128, 256, 512)


# Render the objevtive
imgs = render.render_vis(model, obj, param_f, thresholds=thresholds, transforms=transforms)
show([nd.zoom(img[0], [1,1,1], order=0) for img in imgs])

# test = np.array(imgs)
# test = test.reshape(400)
# test = test[0:400:1]

# fig = plt.figure(frameon=False);
# ax = plt.Axes(fig, [0, 0, 1, 1]);
# ax.set_axis_off();
# fig.add_axes(ax);
# ax.plot(test, 'black');
# ax.set(xlim=(0, 400));
# ax.set(ylim=(0,1))<jupyter_output>1 0.0<jupyter_text>Simple 1D visualizations<jupyter_code># Specify param.image size
param_f = lambda: param.image(400, h=1, channels=1)

transforms = []

# Specify the objective

# neuron = lambda n: objectives.neuron(LAYERS['pool1'][0], n)
# obj = neuron(0)
channel = lambda n: objectives.channel(LAYERS['pool1'][0], n)
obj = channel(0)

# Specify the number of optimzation steps,
thresholds = (128,)


# Render the objevtive
imgs = render.render_vis(model, obj, param_f, thresholds=thresholds, transforms=transforms, verbose=False)

# Display visualization

test = np.array(imgs)
test = test.reshape(400)
test = test[0:400:1]

fig = plt.figure(frameon=False);
ax = plt.Axes(fig, [0, 0, 1, 1]);
ax.set_axis_off();
fig.add_axes(ax);
ax.plot(test, 'black');
ax.set(xlim=(0, 400));
ax.set(ylim=(0,1))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14442793462109954, 'fraction_numerical': 0.04398216939078752, 'mean_word_length': 4.884615384615385, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '214207', 'license': 'MIT', 'n_tokens_mistral': 1334, 'n_tokens_neox': 1239, 'n_words': 312, 'path': 'lucid_work/notebooks/feature_visualization.ipynb', 'repo_name': 'JianiDing/dla_cnn', 'size': '3370'}