Invoke the session only for the required computation Constants Constants are

Invoke the session only for the required computation

This preview shows page 2 - 4 out of 6 pages.

Invoke the session only for the required computation. Constants Constants are created using the constant() function. constant(value, dtype=None, shape=None, name='Const', verify_shape=False) value - Can take any assigned value dtype - Data Type (float / integer) shape - this is optional , it takes the dimensions name - can assign any name to the constant verify_shape - another optional parameter that verifies the dimension of the constant. Example: x = tf.constant(42, name="a", dtype=tf.float32) Variables In TensorFlow all the variables are in-memory buffers that have tensors. These tensors require initialization to be consumed in the data flow graph. Variables become a part of the graph by calling the variable() construct. They are used to keep and update the parameters used in the models. Variables can be defined as shown below. a = tf.Variable(tf.zeros([5]), name="a") Another way of using variable is z = tf.Variable(tf.add(x, y), trainable=False) Placeholders Placeholders are values that are initially unassigned but get initialized when the session is invoked. The main use of placeholders is they allow the creation of operations and the computational graph sans needing to provide the data before that.
Image of page 2
The required data can be added during the actual runtime from any external sources. Syntax: placeholder(dtype, shape=None, name=None) ------------- HandsOn - TensorFlow Basic Hands_on matrix1 = np.array([[1,3,4],[3,5,3],[4,5,3]]) matrix2 = np.array([[2,5,7],[3,6,8],[2,6,9]]) tf_mat1 = tf.convert_to_tensor(matrix1, dtype=tf.float64) tf_mat2 = tf.convert_to_tensor(matrix2, dtype=tf.float64) a = tf_mat1 b = tf_mat2 init = a * b final_mat1 = tf.multiply(a, b) b_inv = tf.transpose(b)final_mat2 = tf.tensordot(a, b_inv, 1)--------------- Which one of the following would you use to pass data to placeholder during
Image of page 3
Image of page 4

You've reached the end of your free preview.

Want to read all 6 pages?

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture