Migrating to TensorFlow 2.0

TensorFlow 2.0 preview version has just been announced. In this blog post, I’ll summarize what to expect for migrating your code to this new version.

Official resources

Migrating your code automatically

Here’s the good news: TensorFlow 2.0 provides an automatic migration tool. After installing the new version, you can run:

tf_upgrade_v2 --intree ./project_directory --outtree ./project_directory_updated

So what is this tool doing ? It’s mostly moving your code to tf.compat.v1 and changing the name of the arguments if necessary. The script should update your code to make it work, but will not make it follow TensorFlow 2.0 best practices.

Moreover, it does not work with tf.contrib. Indeed, this module has been removed from TensorFlow 2.0, with most of the APIs moved to TensorFlow core or external repositories. See the details here

Migrating your code manually

While your code will work using tf.compat.v1, to follow TensorFlow 2.0 new philosophy you will have to update your code manually. Here are the biggest changes:

A very good explanation is available in the official TensorFlow 2.0 guides here.

Conclusion

Note that this is only a preview version: expect some bugs and inconsistencies. Nevertheless, it should give you a good vision on this substantial TensorFlow update. In upcoming blogposts, I’ll detail each of the new changes in TensorFlow.

I’m still unsure about the future of TensorFlow Estimators and TPUs. If you have any info about this, reach out to me on Twitter.