TensorFlow2.x 和 TensorFlow1.x 的函数转换

发布于:2022-12-21 ⋅ 阅读:(1001) ⋅ 点赞:(0)

Tensorflow从1.0升级到2.0之后,有很多方法的使用发生了改变,这里给大家总结了常用的函数的转换:

1、针对 module 'tensorflow' has no attribute 'gfile' 的出错:

tf.gfile.xxx 转换为 tf.compat.v1.gfile.xxx

2、针对 module 'tensorflow' has no attribute 'python_io' 的出错:

tf.python_io.xxx 替换为 tf.compat.v1.python_io.xxx

3、 针对 module 'tensorflow' has no attribute 'logging' 的出错:

tf.logging.xxx 替换为 tf.compat.v1.logging.xxx

4、针对 module 'tensorflow' has no attribute 'parse_single_example' 的出错:

tf.parse_single_example() 改为 tf.io.parse_single_example()

5、针对 module 'tensorflow' has no attribute 'to_int32' 的出错:

tf.to_int32(my_tensor) 改为 tf.cast(my_tensor, tf.int32)

6、针对 module 'tensorflow' has no attribute 'variable_scope' 的出错:

tf.variable_scope() 改为 tf.compat.v1.variable_scope()

7、针对 module 'tensorflow' has no attribute 'get_variable' 的出错:

tf.get_variable() 改为 tf.compat.v1.get_variable()

8、针对 module 'tensorflow' has no attribute 'truncated_normal_initializer' 的出错

tf.truncated_normal_initializer() 改为 tf.compat.v1.truncated_normal_initializer()

9、针对 module 'tensorflow' has no attribute 'assert_less_equal' 的出错

tf.assert_less_equal() 改为 tf.compat.v1.assert_less_equal()

10、针对 module 'tensorflow' has no attribute 'layers' 的出错

tf.layers.xxx 改为 tf.compat.v1.layers.xxx

注意:若上述还没有涉及到的,可以去Tensorflow的官网查询,下面是中文文档地址:

https://www.tensorflow.org/api_docs/python/tf

本文含有隐藏内容,请 开通VIP 后查看

网站公告

今日签到

点亮在社区的每一天
去签到