Hands-on with Tensorflow 2.0 - Part I

Updated: Nov 29, 2020

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 talking 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 define the direction of the 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 the eager mode by default which enables easy debugging.

You can replicate the Tensorflow 1.xx sessions by using the @tf.function decorator which retains all the advantages of Tensorflow graph based execution.

Placeholders and feed dicts that are used in sessions will function using TF compatibility mode but have 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 an 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


Hope you liked my article. If you have any questions and doubts related to this topic or any topic in AI and machine learning, do let me know in the comment section, and I will be more than happy to help you out. Do hit like on this article and share it among your friends who are in AI. Follow us on Instagram and Twitter. Let's democratize AI.

23 views0 comments