我使用 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/