将激活层添加到Keras Add()图层并将此图层用作模型的输出

问题描述 投票:0回答:1

我试图将softmax activation layer应用于Add()层的输出。我试图让这个图层成为我的模型的输出,我遇到了一些问题。

似乎Add()层不允许使用激活,如果我做这样的事情:

predictions = Add()([x,y])
predictions = softmax(predictions)
model = Model(inputs = model.input, outputs = predictions)

我明白了:

ValueError: Output tensors to a Model must be the output of a Keras `Layer` (thus holding past layer metadata). Found: Tensor("Softmax:0", shape=(?, 6), dtype=float32)
python-3.x keras deep-learning
1个回答
3
投票

它与Add层无关,你直接在Keras张量上使用K.softmax,这不起作用,你需要一个实际的层。您可以使用Activation图层:

from keras.layers import Activation

predictions = Add()([x,y])
predictions = Activation("softmax")(predictions)
model = Model(inputs = model.input, outputs = predictions)
© www.soinside.com 2019 - 2024. All rights reserved.