1. Placeholders : For data and labels that will be fed to graph
  2. Variables : Weights and bias
  3.  TesorBoard : Good debugging tool.  Add a couple of lines to training script and we can visualize.
  4. Tensors  : Tensors represent data.
    3 # a rank 0 tensor; this is a scalar with shape []
    [1. ,2., 3.] # a rank 1 tensor; this is a vector with shape [3]
    [[1., 2., 3.], [4., 5., 6.]] # a rank 2 tensor; a matrix with shape [2, 3]
    [[[1., 2., 3.]], [[7., 8., 9.]]] # a rank 3 tensor with shape [2, 1, 3]
    
  5. Acessing tensor objects from python
    import tensorflow as tf

    This gives python acess to all the tensor classes, methods and objects

  6. Running TensorFlow : It requires two step process
    1. Define the tensorflow graph first. e.g
      node1 = tf.constant(3.0, tf.float32)
      node2 = tf.constant(4.0) # also tf.float32 implicitly
      print(node1, node2)
      

      This however will not print  nodel and node2 as 3.0 and 4.0, because we have just  created the tensorflow object only till now.
      It is corolloray to compiling in a program.

    2. Run it : To display we need to run the program which in tensorflow we do it as
      sess = tf.Session()
      print(sess.run([node1, node2]))
      

      By passing “node1” and “node2” in the “sess.run” we are instructing the tensorflow to evaluate “node1” and “node2” values, which we then print with the “print(sess.run ….)” statement. We can also compute “node1” only if we want to

    3. Visualising TensorFlow :  We can visualise the tensorflow operations, if we need to  via TensorBoard.
      getting_started_add
    4. Parameterisation of TensorFlow : We can do so by using placeholder. e.g
      a = tf.placeholder(tf.float32)
      b = tf.placeholder(tf.float32)
      adder_node = a + b  # + provides a shortcut for tf.add(a, b)
      
      # Run it via
      print(sess.run(adder_node, {a: 3, b:4.5}))
      print(sess.run(adder_node, {a: [1,3], b: [2, 4]}))
      
      #Output
      [7.5]
      [3 , 7]
      
    5. TensorFlow variables : Variables that can be changed by the Tensor-Flow during the runtime. e.g Weight will be updated periodically during the runtime  within the tensorflow operation.
      W = tf.Variable([.3], tf.float32)
      b = tf.Variable([-.3], tf.float32)
      x = tf.placeholder(tf.float32)
      linear_model = W * x + b

      IMP : Variables must be explicitly initialized prior to  run.e.g

      init = tf.global_variables_initializer()
      sess.run(init)
      print(sess.run(linear_model, {x:[1,2,3,4]}))
      
      # Output
      [ 0.          0.30000001  0.60000002  0.90000004]
    6. Tensorflow constants  :  Compared to the variables, constant cannot change.
    7. Tensorflow Session.run() vs Tensor.eval() : If t is a object , t.eval()  is is shorthand for sess.run(t)
      # Using `Session.run()`.
      sess = tf.Session()
      c = tf.constant(5.0)
      print sess.run(c)
      
      # Using `Tensor.eval()`.
      c = tf.constant(5.0)
      with tf.Session():
        print c.eval()
      
    8. TensorFlow Random Values
      # Create a random  value tensor with shape [2,3]  
      #and mean -1 and standard deviation 4
      norm = tf.random_normal([2, 3], mean=-1, stddev=4)
      
    9. TensorFlow Random variables
      # Create a Random tensor variable with shape [2,3] and mean -1
      # and standard deviation 1
      var_rand_norm = tf.Variable( tf.random_normal([2, 3], -1.0, 1.0))

Ref:

https://www.tensorflow.org/get_started/get_started

Advertisements