Techniques for Deep Learning in TensorFlow



**TensorFlow Hands-on Tutorial**


**Outline**

  • Clues in TensorFlow
  • Convolutional Neural Network (CNN) on Cifar-10
  • First Model in TensorFlow
  • ** Techniques for Deep Learning in TensorFlow **
  • Inception V3
  • CNN for Text Classification
  • Hidden Markov Model in TensorFlow
  • Image Captioning in TensorFlow



**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"

Variable scopes control variable (re)use


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

Understanding get_variable

Behavior depends on whether variable reuse enabled

Case 1: reuse set to false

  • Create and return new variable

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

  • Search for existing variable with given name. Raise ValueError if none found

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.

'Saver' op to save and restore all the variables


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 [ ]: