Tensorflow 1.0 vs Tensorflow 2.0

Fabian Christopher
featurepreneur
Published in
2 min readJun 1, 2021

Introduction

Hey There! TensorFlow 2 focuses on simplicity and ease of use, with updates like eager execution, intuitive higher-level APIs, and flexible model building on any platform. There are multiple changes in TensorFlow 2.0 to make TensorFlow users more productive.

TensorFlow 2.0 removes redundant APIs, makes APIs more consistent (Unified RNNs, Unified Optimizers), and better integrates with the Python runtime with Eager execution.

Major Changes in Tensorflow 2.0

Some of the prominent changes that have been implemented in Tensorflow 2 are:

  • API Cleanup
  • Eager execution
  • Omission of globals
  • Functions replace sessions

Recommendations for utilizing Tensorflor 2 Better

Here are some of the important ways to make your Tensorflow 2 Transition smooth and hassle-free:

  • Refactor your code into smaller functions
  • Use Keras layers and models to manage variables
  • Combine tf. data.Datasets and tf. function
  • Take advantage of AutoGraph with Python control flow
  • tf. metrics aggregates data and tf. summary logs them
  • Use tf.config.experimental_run_functions_eagerly() when debugging

Migrating your TensorFlow 1 code to TensorFlow 2 Manually

If you are using a low-level Tensorflow API, then it’s time to upgrade your code, making it simpler, more performant, and easier to maintain. Here’s how to do it manually!

Migrate your Code

  • Replace v1.Session.run calls
  • Use Python objects to track variables and losses
  • Upgrade your training loops
  • Upgrade your data input pipelines
  • Migrate off compat.v1 symbols

Migrate your models

  • Low-level variables & operator execution
  • Models based on tf.layers
  • Mixed variables & v1.layers
  • Using Slim and contrib.layers

Migrating your TensorFlow 1 code to TensorFlow 2 Automatically

The TensorFlow team has created the tf_upgrade_v2 utility to help transition legacy code to the new API automatically

To Upgrade multiple files/folders.

Run in the following command in the terminal opened in the root folder.

tf_upgrade_v2 \
--intree my_project/ \
--outtree my_project_v2/ \
--reportfile report.txt

To Upgrade a single file.

Run the following command in the terminal opened in the root folder.

tf_upgrade_v2 
— infile <input_file_name/payj>
— outfile <output_file_name/path>.py```

More about Tensorflow 2.0

Tensorflow 2.0 Documentation

To check out more about Tensorflow 2.0, follow the link below:

My Tensorflow 2.0 Learning Documentation

Conclusion

Thanks for stopping by!! Tensorflow 2.0 hosts a plethora of new features that make machine learning fun and simplified! Do check out my other articles where I cover topics such as deep learning and other trending technologies.

Stay Safe!! Happy Learning!!

You can check out my Linkedin at https://www.linkedin.com/in/fabchris10/

--

--