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 3.x 获取Keras变量的列表_Python 3.x_Tensorflow_Keras - Fatal编程技术网

Python 3.x 获取Keras变量的列表

Python 3.x 获取Keras变量的列表,python-3.x,tensorflow,keras,Python 3.x,Tensorflow,Keras,我想比较Keras模型中的变量和TensorFlow检查点中的变量。我可以得到如下的TF变量: vars\u in\u checkpoint=tf.train.list\u变量(os.path.join(“./model.ckpt”) 如何从我的model中获取要比较的Keras变量?您可以通过model.weights(tf.Variable实例列表)获取Keras模型的变量。要获取变量名称,您需要从模型层的weight属性访问它。大概是这样的: names=[weight.name代表模型中

我想比较Keras模型中的变量和TensorFlow检查点中的变量。我可以得到如下的TF变量:

vars\u in\u checkpoint=tf.train.list\u变量(os.path.join(“./model.ckpt”)


如何从我的
model
中获取要比较的Keras变量?

您可以通过
model.weights
(tf.Variable实例列表)获取Keras模型的变量。

要获取变量名称,您需要从模型层的weight属性访问它。大概是这样的:

names=[weight.name代表模型中的层。layers代表层中的权重。weights]

为了得到重量的形状:

weights=[weight.shape表示模型中的权重。get_weights()]