Migrating to TensorFlow 2.0
Sun, Jan 13, 2019TensorFlow 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
- 2.0 first official announcement
- Preview version announcement
- 2.0 docs
- 2.0 design documents explaining the new APIs
- 2.0 guides and tutorials (might be moved, permalink)
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:
- as stated above,
tf.contrib
will disappear - using eager execution is recommended (see example notebook)
- the
tf.Session
API will disappear in favor oftf.function
(see example notebook) tf.layers
will disappear, model definition should be done usingtf.keras
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.