python - Keras TensorBoard 可视化Conv Kernels

标签 python keras tensorboard

我使用 Keras 和 TensorFlow 作为后端。 现在我想使用 TensorBoard 回调来可视化我的转换层内核。 但我只能看到 TensorBoard 中的第一个卷积层内核和最后的密集层。 对于其他卷积层,我只能使用偏差值,而不是内核。

这是我的 Keras 模型的示例代码。

tb = TensorBoard(
    log_dir=log_dir, 
    histogram_freq=epochs, 
    write_images=True)

# Define the DNN
model = Sequential()
model.add(Conv2D(filters=16, kernel_size=3, input_shape=(width, height, depth), name="conv1"))
model.add(Activation("relu"))
model.add(Conv2D(filters=16, kernel_size=3, name="conv2"))
model.add(Activation("relu"))
model.add(MaxPool2D())

model.add(Conv2D(filters=32, kernel_size=3, name="conv3"))
model.add(Activation("relu"))
model.add(Conv2D(filters=32, kernel_size=3, name="conv4"))
model.add(Activation("relu"))
model.add(MaxPool2D())

model.add(Flatten())
model.add(Dense(128))
model.add(Activation("relu"))
model.add(Dense(num_classes, name="features"))
model.add(Activation("softmax"))

# Print the DNN layers
model.summary()

# Train the DNN
lr = 1e-3
optimizer = Adam(lr=lr)
model.compile(loss="categorical_crossentropy", optimizer=optimizer, metrics=["accuracy"])
model.fit(x_train, y_train, verbose=1, 
batch_size=batch_size, epochs=epochs, 
validation_data=(x_test, y_test), 
callbacks=[tb])

这就是我在 TensorBoard 中看到的。 (我最小化了第一个转换层的内核) TB Screenshot

我缺少什么来可视化我的所有内核?

最佳答案

这是 Tensorboard 回调的预期行为(但文档中未指定)。请参阅此答案 related bug report of Tensorboard GitHub page :

The TensorBoard Keras callback calls tf.summary.image without overriding the default for max_outputs, so there’s no way to visualize more than the first 3 kernels via the callback at this time.

您需要通过自己调用tf.summary.image来可视化内核。

关于python - Keras TensorBoard 可视化Conv Kernels,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53352215/

相关文章:

python - VS Code Intellisense 不适用于 Conda Python 环境

python - sympy 中的链式法则

python - 即使严格的输入有效,表单验证上的 Django TestCase 也会失败

python - 密集层的 LSTM 初始状态

python - 将 2D 元素的大列表转换为 3D NumPy 数组 - 内存问题

tensorflow - 如何使用张量板分析 keras 预测调用

python - 如何编写静态 python getitem 方法?

python - Tensorflow:如何提取 attention_scores 用于绘图?

tensorflow - 无法从命令提示符运行 Tensorboard

pytorch - 如何在 pytorch 1.1.0 JIT 编译器中启用 Dict/OrderedDict/NamedTuple 支持?