Chapter 7. Other New Features of TensorFlow 2.x

Many things changed from TensorFlow 1.x to 2.x. Some of them were minor changes so that a dedicated chapter didn’t make sense, but they are important enough to be covered here.

API Cleanup

In TensorFlow 2.x the API has been simplified by removing deprecated components and duplicates. Over the years, an abundance of useful packages have added up in the tf.contrib package in a relatively unordered manner. The main reason for this uncontrolled growth was the relatively liberal policy on how third-party contributions to the source code base have been accepted. This was positive on the one hand since it facilitated innovation, but it made this restructuring and cleanup a necessity.

One drawback of the cleanup is the introduction of API backward incompatibilities. In other words, TensorFlow 1.x code doesn’t necessarily run on TensorFlow 2.x without modification. Luckily, a migration script can do most of the work for you. This is called the tf_upgrade_v2 utility, which takes care of reordering arguments, renaming symbols, and changing default values for parameters to avoid tedious and error-prone manual migration. One drawback of the tool is that it uses the tf.compat.v1 package for some of the migrated code.

This package will definitely go away in the near future, although it was announced that it will stay until TensorFlow 2.x releases. This means that the problem is only postponed and not solved in those cases, but at least you are ...

Get What's New In TensorFlow 2.x? now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.