tensorflow 2.0.0 运行 1.0.0的代码:
(只需在代码前面加上如下代码)
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()
将v1版升级为v2版工具:
1.升级单个文件:
tf_upgrade_v2 --infile "1.x的代码文件" --outfile "2.x的代码文件"
2.升级所有文件:
tf_upgrade_v2 --intree foo/ --outtree foo-upgraded/
- 例: 将下列v1代码升级为v2
文件v1.py:
import tensorflow as tf
foo = tf.placeholder(tf.int32,shape=[1], name='foo')
bar = tf.constant(2,name='bar')
result = foo