【问题标题】:Adding an activation layer to Keras Add() layer and using this layer as output to model向 Keras Add() 层添加一个激活层,并将该层用作模型的输出
【发布时间】:2019-04-12 06:12:50
【问题描述】:

我正在尝试将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】:

    它与 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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-11-13
      • 2019-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-25
      相关资源
      最近更新 更多