Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.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
访问Keras中的层变量_Keras - Fatal编程技术网

访问Keras中的层变量

访问Keras中的层变量,keras,Keras,如果我按照指南进行操作并与TensorFlow工作流()集成,您将无法访问权重变量,因为我们不会按照指南中所示构建模型。我们只是在使用图层。当我们将它用作TensorFlow的简化接口时,不需要编译那么我们如何访问权重(变量)? 因为如果我们像指南一样使用TensorFlow,我们不会调用模型或编译,而只是使用层来构建 如果您谈论的是模型定义为: x = Dense(128, activation='relu')(img) x = Dense(128, activation='relu')(x)

如果我按照指南进行操作并与TensorFlow工作流()集成,您将无法访问权重变量,因为我们不会按照指南中所示构建模型。我们只是在使用图层。当我们将它用作TensorFlow的简化接口时,不需要编译那么我们如何访问权重(变量)?


因为如果我们像指南一样使用TensorFlow,我们不会调用
模型
编译
,而只是使用层来构建

如果您谈论的是模型定义为:

x = Dense(128, activation='relu')(img)
x = Dense(128, activation='relu')(x)
preds = Dense(10, activation='softmax')(x)  # output layer with 10 units and a softmax activation
那么您是对的,您无法访问变量,但这是因为我们没有给层命名(我们只跟踪张量
x

如果要访问变量,同时使用类似的符号,则必须执行以下操作:

l1 = Dense(128, activation='relu')
l2 = Dense(128, activation='relu')
out = Dense(10, activation='softmax')
preds = out(l2(l1(img)))
然后您可以通过
l1.weights
访问变量,例如
l1



如果您对使用
Sequential
时如何访问变量感兴趣,请使用:
model.layers[i]。weights
where
i
是您感兴趣的层的索引。

您能在想要获取变量的位置添加代码吗?