如何在 TensorFlow 中测试各个层?

How can I test individual layers in TensorFlow?

我根据 DEEP MNIST Expert 教程构建了一个 7 层卷积网络。我又添加了两个卷积层。

一切运行良好,但我想尝试将 1024 x 10 数组直接输入到全连接层,并绕过卷积层。

有没有不用重建整个网络的方法?

在卷积层和全连接层之间,为全连接层的输入创建一个占位符:input_to_fc = tf.placeholder_with_default(previous_layer, shape=(None, 1024*10))。您可以通过将输入直接馈送到 input_to_fc 张量来绕过卷积层。

示例:

...
conv = tf.layers.conv2d(...)
flatten = tf.layers.flatten(...)
input_to_fc = tf.placeholder_with_default(flatten, shape=OUTPUT_SHAPE_OF_PREVIOUS_LAYER))
fc = tf.layers.dense(input_to_fc, ...)