我有以下tensorflow 1.0代码:
import tensorflow as tf
feature_cols = tf.contrib.learn.infer_real_valued_columns_from_input(X_train)
dnn_clf = tf.contrib.learn.DNNClassifier(hidden_units=[300,100], n_classes=10,
feature_columns=feature_cols)
dnn_clf = tf.contrib.learn.SKCompat(dnn_clf) # if TensorFlow >= 1.1
dnn_clf.fit(X_train, y_train, batch_size=50, steps=40000)
当我尝试运行转换器时:
tf_upgrade_v2 --infile mlp.py --outfile mlp2.py
我得到以下错误:
--------------------------------------------------------------------------------
File: mlp.py
--------------------------------------------------------------------------------
mlp.py:3:15: ERROR: Using member tf.contrib.learn.infer_real_valued_columns_from_input in
deprecated module tf.contrib. tf.contrib.learn.infer_real_valued_columns_from_input cannot be converted automatically. tf.contrib will not be distributed with TensorFlow 2.0, please
consider an alternative in non-contrib TensorFlow, a community-maintained repository such as
tensorflow/addons, or fork the required code.
mlp.py:4:10: ERROR: Using member tf.contrib.learn.DNNClassifier in deprecated module tf.contrib. tf.contrib.learn.DNNClassifier cannot be converted automatically. tf.contrib will not be distributed with TensorFlow 2.0, please consider an alternative in non-contrib TensorFlow, a community-maintained repository such as tensorflow/addons, or fork the required code.
mlp.py:6:10: ERROR: Using member tf.contrib.learn.SKCompat in deprecated module tf.contrib. tf.contrib.learn.SKCompat cannot be converted automatically. tf.contrib will not be distributed with TensorFlow 2.0, please consider an alternative in non-contrib TensorFlow, a community-maintained repository such as tensorflow/addons, or fork the required code.
我的问题是:当升级脚本失败时,如何将tensorflow 1.0代码转换为tensorflow 2.0
一些Tensorflow 1.x库被移到Tensorflow/addons
,而在Tensorflow 2.x中,很少有库被Tensorflow.Estimator
替换。tf_upgrade_v2
脚本不会将代码从Tfv1.x完全升级到Tfv2.x。此脚本将通过将现有的TensorFlow 1.x Python脚本转换为TensorFlow 2.0来加速升级过程。
在这种情况下,tf.contrib.learn
被Estimator取代。
TF2.x兼容代码:替换
tf.contrib.learn.DNNLinearCombinedRegressor
带有
tf.estimator.DNNLinearCombinedRegressor
查看此链接了解更多信息