Skip to content

Commit

Permalink
Update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
EderSantana committed Oct 4, 2015
1 parent c4571b5 commit fa4159a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
5 changes: 3 additions & 2 deletions agnez/keras_callbacks.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'''This provides visualization tools for Keras.'''
from . import grid2d, DeepPref, video_grid

from theano import function
from keras.callbacks import Callback
from bokeh.plotting import (cursession, figure, output_server,
push, show)
Expand Down Expand Up @@ -110,11 +111,11 @@ class Grid2D(BokehCallback):
def __init__(self, W, num_weights=100, name='experiment',
fig_title='grid', url='default',):
BokehCallback.__init__(self, name, fig_title, url)
self.W = W
self.W = function([], W)
self.num_weights = num_weights

def get_image(self):
W = self.W.get_value().T
W = self.W()
return grid2d(W[:self.num_weights])


Expand Down
13 changes: 3 additions & 10 deletions examples/bokeh_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
from keras.utils import np_utils
from keras.utils.theano_utils import shared_scalar

from seya.optimizers import ISTA, Adamista

from agnez.keras_callbacks import Grid2D, Plot, PreferedInput

'''
Expand Down Expand Up @@ -68,19 +66,14 @@
model.add(Activation('softmax'))

# rms = RMSprop()
# opt = ISTA(lr=.001, momentum=.9, lambdav=shared_scalar(.0005),
# soft_threshold=True)
opt = Adamista(lambdav=shared_scalar(.0005))
opt = Adam()
model.compile(loss='categorical_crossentropy', optimizer=opt)

'''
We will visualize the weights of the first layer. Note that Grid2D assumes
each filter is in a different row, this is why we transpose W.
'''
# We will visualize the weights of the first layer. Note that Grid2D assumes
# each filter is in a different row, this is why we transpose W.
ex_name = 'keras_example'
grid = Grid2D(name=ex_name, fig_title="First layer weights", url='default',
W=model.layers[0].W) # TODO transpose W by default?
W=model.layers[0].W.T) # TODO transpose W by default?
# think grid2d for hidden layers
pref = PreferedInput(name=ex_name, fig_title="Second layer preferences",
url='default', model=model, layer=3) # Layer 3 is the
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ wheel==0.23.0
pillow
numpy
matplotlib
seaborn
theano

0 comments on commit fa4159a

Please sign in to comment.