当前位置:主页 > 软件编程 > Python代码 >

TensorFlow低版本代码自动升级为1.0版本

时间:2021-06-02 08:23:15 | 栏目:Python代码 | 点击:

Reference:
https://www.tensorflow.org/install/migration

tensorflow 更新到1.0之后,0.n版本不兼容,除了手动更改代码之外,tensorflow官方还提供了自动更新的脚本。

下载链接:https://github.com/tensorflow/tensorflow/tree/master/tensorflow/tools/compatibility

使用方法:

更新一个文件:

原本代码为foo.py, 使用tf_upgrade.py自动升级为1.0版本,新的文件名为foo-upgraded.py:

tf_upgrade.py --infile foo.py --outfile foo-upgraded.py

目录下的所有文件都更新:

 tf_upgrade.py --intree InputDir --outtree OutputDir

目录下的所有文件都更新,并复制除了python文件之外的其他文件到新文件夹:

运行之后所有.py文件都会更新并放在OutputDir目录下,如果想要目录中的其他文件(.txt等)也复制到新的文件夹,可以设置

copyotherfiles为True:
tf_upgrade.py --intree InputDir --outtree OutputDir --copyotherfiles True

更新完毕后脚本会自动生成一个log文件,其中包含了更新的内容。

third_party/tensorflow/tools/compatibility/test_file_v0.11.py Line 125

Renamed keyword argument from `dim` to `axis`
Renamed keyword argument from `squeeze_dims` to `axis`

  Old:          [[1, 2, 3]], dim=1), squeeze_dims=[1]).eval(),
                    ~~~~  ~~~~~~~~~~~~~
  New:          [[1, 2, 3]], axis=1), axis=[1]).eval(),
                    ~~~~~  ~~~~~

拓展阅读

tf_upgrade.py 有一些局限性:

有些结构必须手动替换,例如:

tf.get.variable_scope().reuse_variables() 

替换为:

with tf.variable_scope(tf.get.variable_scope(),reuse=True):

您可能感兴趣的文章:

相关文章