【问题标题】:Keras: single input layer for repeated multi inputsKeras:用于重复多输入的单输入层
【发布时间】:2018-07-13 21:22:04
【问题描述】:

所以,我得到了这个多输入模型,它有 6 个相同形状的相同输入。现在如果我必须使用这个模型,我必须将我的输入数据乘以输入层的总数,即 6。我想知道我是否可以在此之上添加另一个层,并且可以传递单个输入来连接所有这 6 个输入。我不知道如何做到这一点!有什么想法吗?

【问题讨论】:

  • 你的意思是你想连接它们?
  • 不,我认为他不想连接,因为输入是相同的。你能详细说明问题吗?你想用这个做什么操作?
  • 为什么不能只重用一个输入层?

标签: python tensorflow model keras layer


【解决方案1】:

问题是这样的:我有一个 "BASE" 多输入模型,其中所有输入都是相同的,因为这个 "BASE" 模型只是一个组合碰巧共享相同类型输入的多个模型!现在,当使用这个 "BASE" 模型进行分类时,我必须为每个输入层提供 [input_data x "total_inputs"],这是我不想要的要做,在分类百万句子时说!

因此,理想的解决方案是只有一个输入与所有 "BASE" 模型输入相连!!

好的,下面是它的完成方式:

  1. 创建一个新的top_model,它将接受单个输入并生成多个相同的输出。这可以通过Lambda 层来完成。

    single_input = layers.Input(input_shape)
    multi_output = layers.Lambda(lambda x: [x] * total_numbers_of_base_inputs)(single_input)
    top_model = Model(inputs=single_input, outputs=multi_output)
    
  2. 使用top_model 输入和您的multi_input_base_model 如下所示创建新的single_input 模型。

    new_model = Model(inputs=top_model.input, outputs=multi_input_base_model(top_model.output))
    

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-03-31
    • 1970-01-01
    • 2017-09-19
    • 2021-05-20
    • 1970-01-01
    • 2017-03-01
    • 1970-01-01
    相关资源
    最近更新 更多