Example #1
0
Description: The goal of this script is to analyze the trained neural network
regarding their weights.
"""

from __future__ import division
from tools import data_loader, model_io, render, data_analysis
import matplotlib.pyplot as plt
import numpy as np
import settings
import math
import mpl_toolkits.axes_grid1 as axes_grid1

# load trained neural network (nn)
nnName = 'nn_Linear_4096_4_Rect_Linear_4_2_SoftMax_(batchsize_10_number_iterations_20000).txt'
# nnName = 'nn_Linear_1024_2_Rect_Linear_2_2_SoftMax_(batchsize_10_number_iterations_10000).txt'
nn = model_io.read(settings.modelPath + nnName)

# I do not want to load the data every time, therefore the if statement
if 'X' not in locals():
    # load data
    X, Y = data_loader.load_data()

# choose some test data
idx = 0
x = X['train'][[idx]]
y = Y['train'][[idx]]
nnPred = nn.forward(x)
# print nnPred
# lrpScores = nn.lrp(nnPred, 'alphabeta', 2)
# print np.sum(lrpScores)
#plt.matshow(render.vec2im(x[0] + innerCircleSq))
Example #2
0
"""

#from tools import data_loader, model_io, render, data_analysis
from tools import model_io, render, data_analysis
import matplotlib.pyplot as plt
from matplotlib.widgets import Slider, Button, RadioButtons
import numpy as np
import settings
#import math
import os



# load trained neural network (nn)
nnName = 'nn_Linear_1024_2_Rect_Linear_2_2_SoftMax_(batchsize_10_number_iterations_10000).txt'
nn = model_io.read(os.path.join(settings.modelPath, nnName))

# unique shape rotation of squares and triangles
uniqShapeRot = data_analysis.unique_shapes()
uniqShapeRotSq = uniqShapeRot['square']
uniqShapeRotTr = uniqShapeRot['triangle']
numbRotSq = len(uniqShapeRotSq)
numbRotTr = len(uniqShapeRotTr)

# init figure
fig, axes = plt.subplots(figsize=(15, 5))
plt.axis('off')

# set locations for sliders
axcolor = 'lightgoldenrodyellow'