question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

tf.keras.callbacks.Tensorboard: write_images does not visualize Conv2D weights

See original GitHub issue

I moved this issue from https://github.com/tensorflow/tensorflow/issues/28767

System information

  • Have I written custom code (as opposed to using a stock example script provided in TensorFlow): yes
  • TensorFlow version (use command below): v1.12.2-0-gcf74798993 1.12.2
  • Python version: 3.6.5

Describe the current behavior When I want to have a look at the weights of Conv2D filters in TensorBoard, only their biases get logged (see attached image). I looked for the corresponding source code and found the following snippet: https://github.com/tensorflow/tensorflow/blob/6612da89516247503f03ef76e974b51a434fb52e/tensorflow/python/keras/callbacks.py#L951-L983 The problem seems to be that Conv2D weights have a 4d shape [H_kernel, W_kernel, C_in, C_out], which is not intended as convolutional layers case in the above code.

Describe the expected behavior I would expect that the convolutional weights are visualized. I know this would be a huge amount of images (C_in * C_out), but I think the current behaviour is confusing.

Code to reproduce the issue

import tensorflow as tf

cifar10 = tf.keras.datasets.cifar10

(x_train, y_train), (x_test, y_test) = cifar10.load_data()
x_train, x_test = x_train / 255.0, x_test / 255.0
print(type(x_train))
model = tf.keras.models.Sequential([
    tf.keras.layers.InputLayer(input_shape=(32, 32, 3)),
    tf.keras.layers.Conv2D(filters=16, kernel_size=3, padding='same', activation='relu'),
    tf.keras.layers.Conv2D(filters=32, kernel_size=3, padding='same', activation='relu'),
    tf.keras.layers.Flatten(),
    tf.keras.layers.Dense(128, activation='relu'),
    tf.keras.layers.Dense(10, activation='softmax')
])
model.summary()

tensorboard = tf.keras.callbacks.TensorBoard(log_dir=f"../../../logs", histogram_freq=1,
                                             write_images=True, write_grads=True)
csvlogger = tf.keras.callbacks.CSVLogger('train.log')
model.compile(optimizer=tf.keras.optimizers.Adam(lr=1e-4),
              loss='sparse_categorical_crossentropy',
              metrics=['accuracy'])

model.fit(x_train, y_train, epochs=5, callbacks=[tensorboard, csvlogger], validation_data=(x_test, y_test))

Other info / logs image

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:1
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
nfeltcommented, Jul 16, 2019

cc @caisq FYI re tensor visualization

1reaction
maxstrobelcommented, Jul 16, 2019

Hi @menon92,

No I did not dive deeper into it. However, the issue seems to be also present in TF2.0. If I find time and look deeper into this, I will share my findings.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Keras Tensorboard callback not writing images - Stack Overflow
I am trying to visualize weights of my Keras ...
Read more >
tf.keras.callbacks.TensorBoard | TensorFlow v2.11.0
The log file can become quite large when write_graph is set to True. write_images, whether to write model weights to visualize as image...
Read more >
Visualizing training with TensorBoard - GeeksforGeeks
Visualize model layers and operations with the help of graphs. Provide histograms for weights and biases involved in training. Displaying ...
Read more >
Visualize Models in TensorBoard With Weights & Biases
tf.keras makes it very easier to plug TensorBoard in as a callback. We will see how in a moment. But first, ...
Read more >
tf.keras.callbacks.TensorBoard | TensorFlow
If set to 0, histograms won't be computed. Validation data (or split) must be specified for histogram visualizations. write_graph : whether to visualize...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found