使用 tf_upgrade_v2 命令把 tensorflow1.x 的代码快速转换成 tensorflow2.0

安装 tensorflow 时会自动安装tf_upgrade_v2

tf_upgrade_v2 --infile D:\tensorflowProject\tf01.py --outfile D:\tensorflowProject\tf01_upgraded.py

在这里插入图片描述
report.txt

TensorFlow 2.0 Upgrade Script
-----------------------------
Converted 1 files
Detected 4 issues that require attention
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
File: D:\tensorflowProject\tf01.py
--------------------------------------------------------------------------------
D:\tensorflowProject\tf01.py:92:9: WARNING: tf.nn.embedding_lookup requires manual check. `partition_strategy` has been removed from tf.nn.embedding_lookup.  The 'div' strategy will be used by default.
D:\tensorflowProject\tf01.py:101:8: WARNING: tf.nn.sampled_softmax_loss requires manual check. `partition_strategy` has been removed from tf.nn.sampled_softmax_loss.  The 'div' strategy will be used by default.
D:\tensorflowProject\tf01.py:130:19: WARNING: tf.nn.embedding_lookup requires manual check. `partition_strategy` has been removed from tf.nn.embedding_lookup.  The 'div' strategy will be used by default.
D:\tensorflowProject\tf01.py:185:13: WARNING: *.save requires manual check. (This warning is only applicable if the code saves a tf.Keras model) Keras model.save now saves to the Tensorflow SavedModel format by default, instead of HDF5. To continue saving to HDF5, add the argument save_format='h5' to the save() function.
================================================================================
Detailed log follows:

================================================================================
--------------------------------------------------------------------------------
Processing file 'D:\\tensorflowProject\\tf01.py'
 outputting to 'D:\\tensorflowProject\\tf01_upgraded.py'
--------------------------------------------------------------------------------

84:10: INFO: Renamed 'tf.placeholder' to 'tf.compat.v1.placeholder'
85:10: INFO: Renamed 'tf.placeholder' to 'tf.compat.v1.placeholder'
90:25: INFO: Renamed 'tf.random_uniform' to 'tf.random.uniform'
92:9: INFO: Added keywords to args of function 'tf.nn.embedding_lookup'
92:9: WARNING: tf.nn.embedding_lookup requires manual check. `partition_strategy` has been removed from tf.nn.embedding_lookup.  The 'div' strategy will be used by default.
97:25: INFO: Renamed 'tf.truncated_normal' to 'tf.random.truncated_normal'
101:8: WARNING: tf.nn.sampled_softmax_loss requires manual check. `partition_strategy` has been removed from tf.nn.sampled_softmax_loss.  The 'div' strategy will be used by default.
103:8: INFO: Added keywords to args of function 'tf.reduce_mean'
104:13: INFO: Renamed 'tf.train.AdamOptimizer' to 'tf.compat.v1.train.AdamOptimizer'
127:16: INFO: Added keywords to args of function 'tf.reduce_sum'
130:19: INFO: Added keywords to args of function 'tf.nn.embedding_lookup'
130:19: WARNING: tf.nn.embedding_lookup requires manual check. `partition_strategy` has been removed from tf.nn.embedding_lookup.  The 'div' strategy will be used by default.
132:41: INFO: Added keywords to args of function 'tf.transpose'
138:9: INFO: Renamed 'tf.train.Saver' to 'tf.compat.v1.train.Saver'
140:5: INFO: Renamed 'tf.Session' to 'tf.compat.v1.Session'
144:10: INFO: Renamed 'tf.global_variables_initializer' to 'tf.compat.v1.global_variables_initializer'
185:13: WARNING: *.save requires manual check. (This warning is only applicable if the code saves a tf.Keras model) Keras model.save now saves to the Tensorflow SavedModel format by default, instead of HDF5. To continue saving to HDF5, add the argument save_format='h5' to the save() function.
--------------------------------------------------------------------------------


可见 tf_upgrade_v2 会重命名一些API( tf2.0.0 的API重组导致函数的重命名。)

发布了588 篇原创文章 · 获赞 170 · 访问量 29万+

猜你喜欢

转载自blog.csdn.net/qq_41228218/article/details/105222974