**Outline**
**Complex Models**
Complicated TensorFlow models can have hundreds of variables
tf.variable_scope(): provides simple name-spacing to avoid clashes.
tf.get_variable(): creates/accesses variables from within a variable scope.
Variable scope is a simple type of namespacing that adds prefixes to variable names within scope
In [ ]:
with tf.variable_scope("foo"):
with tf.variable_scope("bar"):
v = tf.get_variable("v", [1])
assert v.name == "foo/bar/v:0"
In [ ]:
with tf.variable_scope("foo"):
v = tf.get_variable("v", [1])
tf.get_variable_scope().reuse_variables()
v1 = tf.get_variable("v", [1])
assert v1 == v
You’ll need to use reuse_variables() to implement Deep Networks
Case 1: reuse set to false
In [ ]:
with tf.variable_scope("foo"):
v = tf.get_variable("v", [1])
assert v.name == "foo/v:0"
Case 2: Variable reuse set to true
In [ ]:
with tf.variable_scope("foo"):
v = tf.get_variable("v", [1])
with tf.variable_scope("foo", reuse=True):
v1 = tf.get_variable("v", [1])
assert v1 == v
**Save and Restore a model using TensorFlow**
In Deep Leaning it is crucial to save your trained model including parameters, weight, and Graph.
In [ ]:
saver = tf.train.Saver()
save_path = saver.save(sess, model_path)
print "Model saved in file: %s" % save_path
In [ ]:
load_path = saver.restore(sess, model_path)
print "Model restored from file: %s" % save_path
Here is an example of how it works Link
Go Back to CNN on Cifar-10 and save your trained model and restor it in the for the test session
In [ ]: