我使用了一个具有以下变量的示例
weights = {
# 5x5 conv, 1 input, 32 outputs
'wc1': tf.Variable(tf.random_normal([5, 5, 1, 32])),
# 5x5 conv, 32 inputs, 64 outputs
'wc2': tf.Variable(tf.random_normal([5, 5, 32, 64])),
# fully connected, 7*7*64 inputs, 1024 outputs
'wd1': tf.Variable(tf.random_normal([7*7*64, 1024])),
# 1024 inputs, 10 outputs (class prediction)
'out': tf.Variable(tf.random_normal([1024, n_classes]))
}
biases = {
'bc1': tf.Variable(tf.random_normal([32])),
'bc2': tf.Variable(tf.random_normal([64])),
'bd1': tf.Variable(tf.random_normal([1024])),
'out': tf.Variable(tf.random_normal([n_classes]))
}这样我就不能使用下面代码来恢复var
wc1 = tf.get_variables("weights[wc1]")那么我如何使用tensorflow恢复变量呢?
发布于 2017-06-23 00:41:29
您只需通过以下方式引用变量
weights["wc1"]tf.get_variable命令以另一种方式使用,如果您想使用它来恢复已经创建的变量,您需要使用reuse = True在变量作用域中,并使用tensorflow与变量关联的名称,而不是python指针。例如:
with tf.variable_scope('var_scope'):
v = tf.Variable(5, shape=(), dtype=tf.float32, name='my_var')
with tf.variable_scope('var_scope', reuse=True):
v_again = tf.get_variable(name='my_var', dtype=tf.float32)现在v和v_again是两个指向相同tensorflow变量的python变量。
https://stackoverflow.com/questions/44703774
复制相似问题