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.reverse() 的参数,因此必须手动修复。
对于参数列表重新排序的方法,如 tf.split() 和 tf.reverse_split(),它会尝试引入关键字参数,但实际上并不能重新排列参数。
有些结构必须手动替换,例如:
tf.get.variable_scope().reuse_variables()
替换为:
with tf.variable_scope(tf.get.variable_scope(),reuse=True):
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
评论(0)