参考:https://www.tensorflow.org/guide/upgrade
TensorFlow创建了 tf_upgrade_v2 工具,可将旧版代码转换为新的API
tf_upgrade_v2 \
--intree my_project/ \
--outtree my_project_v2/ \
--reportfile report.txt
对单个文件:
tf_upgrade_v2
--infile ResNet50.py
--outfile ResNet50_v2.py
对文件夹,将“--infile”改为“--intree”即可。
但是对于contrib模块,需要单独调整:
参考:https://stackoverflow.com/questions/64255154/change-tf-contrib-layers-xavier-initializer-to-2-0-0
the TF2 replacement for
tf.contrib.layers.xavier_initializer()
is tf.keras.initializers.glorot_normal
(Xavier and Glorot are 2 names for the same initializer algorithm) documentation link.
TensorFlow与cuda 对应版本查询: