tensorflow1和2版本兼容性问题解决
如何不卸载2也能使用1的库
今天跑了格开源代码发现是 tensorflow1的库但在2里已经不用。 我的是2版本。
原代码是这样的
import tensorflow as tf
import tensorflow.contrib.slim as slim
def show_all_variables():
# Adapted from original code at
# https://github.com/carpedm20/simulated-unsupervised-tensorflow
model_vars = tf.trainable_variables()
slim.model_analyzer.analyze_vars(model_vars, print_info=True)
这里的tensorflow.contrib.slim在2版本已经消失了
解决代码
import tensorflow.compat.v1 as tf
#import tensorflow.contrib.slim as slim
def show_all_variables():
# Adapted from original code at
# https://github.com/carpedm20/simulated-unsupervised-tensorflow
model_vars = tf.trainable_variables()
tf.disable_v2_behavior(tf.contrib.slim).model_analyzer.analyze_vars(model_vars, print_info=True)
import tensorflow.compat.v1 as tf tf