Google supplies a command-line script called tf_upgrade_v2, which converts version 1.12 files (both .py and .ipynb files) into TensorFlow 2 compatible files.
The syntax for this conversion is as follows:
tf_upgrade_v2 --infile file_to_convert --outfile converted_file
There is a demonstration of this upgrade script in action at https://www.youtube.com/watch?v=JmSNUeBG-PQ&list=PLQY2H8rRoyvzoUYI26kHmKSJBedn3SQuB&index=32&t=71s, and more detailed information regarding it is available at https://github.com/tensorflow/docs/blob/master/site/en/r2/guide/upgrade.md.
It is important to note that you should not update parts of your code manually before running this script.
The script will not fix all of the issues, but the report it produces will identify those issues that must be fixed manually.
In particular, tf.contrib has been removed from...