Initially build inside Google with the name “DistBelief”, Tensorflow has indeed come a long way. It has come up with its new Tensorflow 2.0 and everyone is taking about it. Tensorflow 1.xx was very difficult for newbies to debug and understand with all those tf.session and static computational graphs. Now with Tensorflow 2.0, you can easily debug your code. So, without wasting more time let’s get started.
Difference between Tensorflow 1.xx and Tensorflow 2.0
If you have used Tensorflow 1.xx, you would probably remember the tf.session(), which is used to call its computational graph. In Tensorflow each and every operation are nodes of the graph including the variables too. The graph contains directed edges which defines the direction of flow of information from one node to another node. This is known as Computational Graph.
When tf.session() is invoked, the data is fed into the Computational graph and process the data and generate the output.
In Tensorflow 2.0, we say goodbye to tf.session(), and it has come with tf.keras API as a part of it. Moreover, it runs on eager mode by default which enables easy debugging.
You can replicate the Tensorflow 1.xx sessions by using @tf.function decorator which retains all the advantages of Tensorflow graph based execution.
Placeholders, and feed dicts which is used in sessions will function using TF compatiblity mode, but has been replaced by tf.data which creates input pipelines to read training data.
Now let’s get hands on Tensorflow 2.0
We will build a MNIST model using Tensorflow 2.0. The model will have one flatten layer, one dropout layer and two dense layers.
We can observe that this model structure is very similar to the Keras library’s structure, which in fact gives us the intuition that Tensorflow has incorporated Keras, which has become popular due to its ease of usability.
So, this wraps up Part I of the Tensorflow 2.0 series. You can read more on this topic through the links given below. If you like this article, do give a clap. You can always comment in the comment section in case you have any doubts or contact me on Twitter.
Useful Links -
Tensorflow 2.0 Official Documentation — Link
Migrate your TensorFlow 1 code to TensorFlow 2 — Link