Search code examples
pythontensorflowkerastensorboard

Why Flatten layer has two input in tensorboard


Here is a simple example to reproduce the problem:

model = keras.models.Sequential()
model.add(keras.layers.Flatten(input_shape=[784,]))
model.add(keras.layers.Dense(300, activation="relu"))
model.add(keras.layers.Dense(10, activation="softmax"))

import numpy as np 

X_train = np.random.normal(size=(100, 784))
y_train = np.random.randint(low=0, high=10, size=(100,))

X_valid = np.random.normal(size=(50, 784))
y_valid = np.random.randint(low=0, high=10, size=(50,))

model.compile(optimizer=tf.keras.optimizers.Adam(),
          loss='sparse_categorical_crossentropy',)

tensorboard_cb = tf.keras.callbacks.TensorBoard(
    log_dir='logs', histogram_freq=0, write_graph=True, write_images=False,
    update_freq='epoch', profile_batch=0, embeddings_freq=0,
    embeddings_metadata=None)
history = model.fit(X_train, y_train, epochs=20, validation_data=(X_valid, y_valid), callbacks=tensorboard_cb)

Here is the results on tensorboard:

enter image description here


Solution

  • I re-run your code and found only 1 input on the model chart. Also no dense_2 layer. Perhaps you used the logs dir for more than 1 model, so this confused Tensorboard?

    Try re-running the model, starting with clean logs directory (change name or delete the old one before the run).