Python 为什么在启用“急切执行”时,可训练变量会消失?
如果我运行以下代码(tensorflow 1.15),我可以通过两种不同的方式获得可训练变量的列表Python 为什么在启用“急切执行”时,可训练变量会消失?,python,tensorflow,keras,eager-execution,Python,Tensorflow,Keras,Eager Execution,如果我运行以下代码(tensorflow 1.15),我可以通过两种不同的方式获得可训练变量的列表 from tensorflow.keras.layers import AveragePooling2D, Conv2D, Dense, Flatten, Input from tensorflow.keras.models import Model import tensorflow as tf x_in = Input((32, 32, 1)) x = Conv2D(filters=6, k
from tensorflow.keras.layers import AveragePooling2D, Conv2D, Dense, Flatten, Input
from tensorflow.keras.models import Model
import tensorflow as tf
x_in = Input((32, 32, 1))
x = Conv2D(filters=6, kernel_size=(5, 5), activation='relu', input_shape=(32,32,1))(x_in)
x = AveragePooling2D(pool_size=(2, 2))(x)
x = Flatten()(x)
x = Dense(units=120, activation='relu')(x)
x = Dense(units=10, activation='softmax')(x)
m = Model(inputs=x_in, outputs=x)
v1 = m.trainable_variables
v2 = tf.compat.v1.trainable_variables()
v1
和v2
具有相同的值
如果在创建模型之前添加对tf.compat.v1.enable_eager_execution()
的调用,v2
将变为空tf.compat.v1.trainable_variables()
返回一个空列表
为什么会这样