09.05.2023 Views

pdfcoffee

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

TensorFlow 1.x and 2.x

The intent of this chapter is to explain the differences between TensorFlow 1.x

and TensorFlow 2.0. We'll start by reviewing the traditional programming paradigm

for 1.x and then we'll move on to all the new features and paradigms available in 2.x.

Understanding TensorFlow 1.x

It is generally the tradition that the first program one learns to write in any computer

language is "hello world." We maintain the convention in this book! Let's begin with

a Hello World program:

import tensorflow as tf

message = tf.constant('Welcome to the exciting world of Deep Neural

Networks!')

with tf.Session() as sess:

print(sess.run(message).decode())

Let us go in depth into this simple code. The first line imports tensorflow. The

second line defines the message using tf.constant. The third line defines the

Session() using with, and the fourth runs the session using run(). Note that

this tells us that the result is a "byte string." In order to remove string quotes and

b (for byte) we use the method decode().

TensorFlow 1.x computational graph program

structure

TensorFlow 1.x is unlike other programming languages. We first need to build

a blueprint of whatever neural network we want to create. This is accomplished

by dividing the program into two separate parts: a definition of a computational

graph, and its execution.

[ 51 ]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!