2017-07-25 23 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