Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/354.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 为什么在启用“急切执行”时,可训练变量会消失?_Python_Tensorflow_Keras_Eager Execution - Fatal编程技术网

Python 为什么在启用“急切执行”时,可训练变量会消失?

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

如果我运行以下代码(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, 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()
返回一个空列表

为什么会这样