2017-07-25 90 views
3

当我创建一个简单的Keras型号结构一个Keras Tensorboard图

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']) 

,做回调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]) 

在Tensorboard输出看起来是这样的: enter image description here

在换句话说,这是一个完整的混乱。

  1. 有什么我可以做,使图表输出看起来更加结构化?
  2. 如何用Keras和Tensorboard创建权重直方图?

回答

2

您可以使用K.name_scope('name_scope')创建一个名称范围,以将模型中的图层分组。

例子:

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) 

由于 https://github.com/fchollet/keras/pull/4233#issuecomment-316954784

+1

这似乎并不在Keras 2.0工作。我无法在任何Keras文档中找到name_sope。你有这个工作吗? – Richard

+0

显然,随着keras的最新版本,这不再是必要的。 – Nickpick

+0

您可以使用'with tensorflow.name_scope(“...”):',至少在Tensorflow 1.4+附带的Keras API中。 – avejidah