我用的是tensorflow 2.6
一般来说在tf 2.x中都可以使用tf.compat.v1.xxxxxx来替代原来tf 1.x中的tf.xxxxxx
但有一些函数比较特殊,在tf 2.x中被去掉了,这里列一列遇到的
tf 1.x:tf.contrib.layers.xavier_initializer
tf 2.6:tf.keras.initializers.glorot_normal
Keras 2.2.5:from keras.optimizers import Adam
Keras 2.6.0:from keras.optimizer_v2.adam import Adam
Keras 2.2.5:from keras.utils import to_categorical
Keras 2.6.0:from keras.utils.np_utils import to_categorical
RuntimeError: When eager execution is enabled, var_list must specify a list or dict of variables to save当eager execution开启的时候,loss应该是一个Python函数。
在Tensorflow 2.0 中,eager execution 是默认开启的。
所以,需要先关闭eager execution
import tensorflow as tf
tf.compat.v1.disable_eager_execution()



