【发布时间】:2018-08-25 04:58:31
【问题描述】:
我正在尝试获取 hidden_layer2 的权重矩阵并打印它。 似乎我能够获得权重矩阵,但我无法打印它。
当使用tf.Print(w, [w]) 时,它什么也不打印。
当使用print(tf.Print(w,[w]) 时,它至少会打印出有关张量的信息:
Tensor("hidden_layer2_2/Print:0", shape=(3, 2), dtype=float32)
我也尝试在 with-Statement 之外使用tf.Print(),结果相同。
完整代码在这里,我只是在前馈神经网络中处理随机数据:https://pastebin.com/KiQUBqK4
我的代码的一部分:
hidden_layer2 = tf.layers.dense(
inputs=hidden_layer1,
units=2,
activation=tf.nn.relu,
name="hidden_layer2")
with tf.variable_scope("hidden_layer2", reuse=True):
w = tf.get_variable("kernel")
tf.Print(w, [w])
# Also tried tf.Print(hidden_layer2, [w])
【问题讨论】:
-
你后来运行图表了吗?
tf.Print()是图表上的另一个 OP,在您评估图表之前不会执行。检查this answer。 -
我想我做到了,因为网络产生了输出。我使用 tf.app.run() 来运行我的整个 main 函数。
标签: python tensorflow