【问题标题】:How to specify neurons connection to the next layer in keras?如何在 keras 中指定与下一层的神经元连接?
【发布时间】:2019-05-05 03:25:44
【问题描述】:

我正在尝试使用预先指定的连接在 Keras 中构建神经网络。例如:

partially connected layers

例如,如果我的输入 X 具有特征“a”,我只想在下一层训练神经元“b”。

我不知道如何在 keras 中指定层之间的连接。

谢谢!

【问题讨论】:

  • 您可以使用 keras API 中的 Input 层指定连接。您可以找到更多详细信息here
  • 感谢您的链接。之前看过链接,但是链接中给出的功能性API示例据我了解与我感兴趣的有所不同。我想根据输入特征只训练某些神经元。例如,如果我的输入具有特征“a”,我只想在下一层训练神经元“A”

标签: keras neural-network deep-learning


【解决方案1】:

在您的情况下,您可以使用Lambda 层和merge 的组合。
所以它可以通过类似的方式来完成:

input = Input((6,))
# Split input to 3 streams
a = Lambda(lambda x: x[:, [0,4]], output_shape=(2,))(input)
b = Lambda(lambda x: x[:, 0:5], output_shape=(5,))(input)
c = Lambda(lambda x: x[:, 5], output_shape=(1,))(input)

# Build the hidden layer
hidden = merge([a, c, b], mode='concat')

# Split the hidden output to 2 streams
aa = Lambda(lambda x: x[:, 0:1], output_shape=(2,))(hidden)
d = Lambda(lambda x: x[:, 2], output_shape=(1,))(hidden)

# Build the output layer
output = merge([aa, d], mode='concat')

model = Model(input, output)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-07-14
    • 2015-07-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-02
    • 2018-08-16
    相关资源
    最近更新 更多