Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Structure a Keras Tensorboard graph

When I create a simple Keras Model

model = Sequential()
model.add(Dense(10, activation='tanh', input_dim=1))
model.add(Dense(1, activation='linear'))
model.compile(loss='mean_squared_error', optimizer='adam', metrics=['mean_squared_error'])

and do a callback to Tensorboard

tensorboard = TensorBoard(log_dir='c:/temp/tensorboard/run1', histogram_freq=1, write_graph=True, write_images=False)
model.fit(x, y, epochs=1000, batch_size=1, callbacks=[tensorboard])

The output in Tensorboard looks like this: enter image description here

In other words, it's a complete mess.

  1. Is there anything I can do to make the graphs output look more structured?
  2. How can I create histograms of weights with Keras and Tensorboard?
like image 679
Nickpick Avatar asked Jul 25 '17 16:07

Nickpick


1 Answers

You can create a name scope to group layers in your model using with K.name_scope('name_scope').

Example:

with K.name_scope('CustomLayer'):
  # add first layer in new scope
  x = GlobalAveragePooling2D()(x)
  # add a second fully connected layer
  x = Dense(1024, activation='relu')(x)

Thanks to https://github.com/fchollet/keras/pull/4233#issuecomment-316954784

like image 183
ronnygeo Avatar answered Jan 29 '23 19:01

ronnygeo