## Posts

Showing posts from June, 2017

### How to Cast Integer to Float and Vice Versa in TensorFlow

In this article, we will learn to convert the data types of tensors to integer and float. First, let's create two nodes. node1 = tf.constant(5) # dtype is int32 node2 = tf.constant(6.0) # dtype is float32 Let's multiply the two nodes to create a new node node3 = tf.multiply(node1, node2) This will throw a TypeError: Input 'y' of 'Mul' Op has type float32 that does not match type int32 of argument 'x'. This is because the node1 data type is an integer while the data type of node2 is a float. Multiply method doesn't convert the types of its variables automatically. For now, we need to change them before performing any type of arithmetic operations on them. I hope this changes in the future releases. The correct way is to convert either of the node's type to match the other. Here, we are converting the node1 which is an integer to a float. tf.to_float(node1, name='ToFloat') Replacing the node1 with the above lin

### TensorFlow - How to Use Placeholders

In this article, we will learn about Placeholders in TensorFlow, how to initialize them and how to pass the data to them. While Constants are used to feed data from inside the model, Placeholders are used to feed data from outside the model. In simpler terms, placeholders doesn't provide values while initializing, they are passed during the session. First, Initialize two placeholders. a = tf.placeholder(tf.float32) b = tf.placeholder(tf.float32) Take a look at the initialization, we aren't passing any value to the tensor. Next, let's add them. adder_node = tf.add(a, b) Now, Inside a session we can pass any number of inputs and the model performs operations and gives a value. # Add two numbers sess.run(adder_node, {a: 1.3, b: 5}) # Add two 1x2 matrices sess.run(adder_node, {a: [2, 8], b: [3, 5]}) Below is the code that initializes tensors with placeholders and passes the values at a later stage. Play with it for better understanding.

### What is a Tensor Rank and Tensor Shape - TensorFlow In this article, we will learn about Tensor Ranks and Tensor Shapes. We know a tensor is an n-dimensional array. So, Rank is defined as the number of dimensions of that tensor. And, Tensor Shape represents the size of the each dimension. A tensor with rank 0 is a zero-dimensional array. The element of a zero-dimensional array is a point. This is represented as a Scalar in Math and has magnitude. Eg: s = 48.3 Shape - [] A tensor with rank 1 is a one-dimensional array. The elements of the one-dimensional array are points on a line. This line has magnitude, direction. and is represented as Vector in Math. Vector has n entries. Eg:  v = [1, 9, -6, 7, 0] Shape -  A tensor with rank 2 is a two-dimensional array. The elements of the two-dimensional array are lines on a surface. This surface is represented as a Matrix in Math and has two coordinates. The Matrix contains n x n entries. Eg: m = [[2.4, 5.1], [3.3, 7.9], [8.5, 6.1]] Shape - [3, 2] A tensor

### How to Create Facebook Page  