Our last tutorial focused on introducing TensorFlow. In that article, we covered the basic installation and use of TensorFlow in Java. In this tutorial, our focus is to highlight the TensorFlow Computational Graph components. With that said, let us explore graphs.
Graphs are a basic and crucial component of TensorFlow. They represent data structures that are comprised of applicable operations and defined data. Graphs can also contain keys and values. The keys are like maps that direct to the actual value.
The above picture represents a graph with two data and one operand (multiplication) that performs an operation and stores the result in another container (c).
Applying the above graph diagram in our code we have a representation as follows:
Graph cgraph = new Graph();
The code above initializes the Graph class. Thus, making it possible to access features associated with it.
At the core of TensorFlow are Tensors. TensorFlow operates on multidimensional arrays. Furthermore, It takes several multidimensional array forms such as:
- A Scalar is a 0-dimensional tensor
- A Vector is a 1-dimensional tensor
- A Matrix is a 2-dimensional tensor
Tensors have ranks. The total number of directions a tensor can have in an N-dimensional space is called the Rank of the tensor. In summary, a Scalar has zero ranks, Vector has one rank and a matrix has two ranks.
This represents a graph node that performs computation on tensors. An Operation is a node in a function graph that accepts zero or more Tensor objects as user input or insertion and produces the required zero or more Tensor objects as output. As an example, the code below where we see two inputs (2, and 3) and the “MatMul” operator to give the resultant multiplication output. e.g.,
Mul<TInt32> dblX = tf.math.mul(2, 3);
Lastly, TensorFlow Session encompasses the environment where Operation objects are run and data objects are assessed. Furthermore, sessions are a crucial part of Tensor operation and evaluation. Below is a quick example.
Session newSession = new Session(graph)
Conclusively, we have looked at TensorFlow Graph with a view to explaining in detail the components that makeup TensorFlow. The code for this tutorial is available on our GitHub page.