It is necessary to create a variable set only once for the entire set (and testing). The purpose of variable regions is to modulate subsets of parameters, such as those belonging to layers (for example, when the layer architecture is repeated, the same names can be used within each level).
model. , , :
from __future__ import print_function
X = tf.placeholder("float")
Y = tf.placeholder("float")
print("X:", X.name)
print("Y:", Y.name)
def model(X):
with tf.variable_scope("param"):
w = tf.Variable(0.0, name="weights")
print("w:", w.name)
return tf.mul(X, w)
sess.run(train_op, feed_dict={X: x, Y: y}) train_op X Y. ( ); . , , :
with tf.variable_scope("train"):
print("X:", X.name)
print("Y:", Y.name)
for i in range(100):
for (x, y) in zip(trX, trY):
sess.run(train_op, feed_dict={X: x, Y: y})
, , .
, , get_variable tf.variable_scope:
with tf.variable_scope("param"):
w = tf.get_variable("weights", [1])
print("w:", w.name)