50%(2)1 out of 2 people found this document helpful
This preview shows page 2 - 4 out of 6 pages.
Invoke the session only for the required computation.ConstantsConstants are created using the constant() function.constant(value, dtype=None, shape=None, name='Const', verify_shape=False)value - Can take any assigned valuedtype - Data Type (float / integer)shape - this is optional , it takes the dimensionsname - can assign any name to the constantverify_shape - another optional parameter that verifies the dimension of the constant.Example:x = tf.constant(42, name="a", dtype=tf.float32)VariablesIn 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(), name="a")Another way of using variable isz = tf.Variable(tf.add(x, y), trainable=False)PlaceholdersPlaceholders 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.
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_onmatrix1 = 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_mat1b = tf_mat2init = a * bfinal_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