在keras中表示多个输入的简单方法?

时间:2017-04-02 18:41:00

标签: python for-loop keras

我正致力于CNN实施,其中有多个(72)输入。

每个输入都以相同的方式处理,然后将它们连接在一起。

目前,我已经写出了72的每个输入和过程,它们不仅看起来很丑陋,而且占用了大量空间(大小与功能)。

是否可以使用某些for循环结构定义多个输出?

我只需要这样做:

input = Input(shape(1,78,3))
conv_1_0 = Conv1D(filters = 32, kernel_size = (1,6) , padding = "same" , activation = "relu" , name = "conv_1d_1_0")(input)

对于72种不同的输入,但所有输入都具有相同的形状。

目前,我有

input0 = Input(shape(1,78,3))
input1 = Input(shape(1,78,3))
input2 = Input(shape(1,78,3))

conv_1_0 = Conv1D(filters = 32, kernel_size = (1,6) , padding = "same" , activation = "relu" , name = "conv_1d_1_0")(input0)
conv_1_1 = Conv1D(filters = 32, kernel_size = (1,6) , padding = "same" , activation = "relu" , name = "conv_1d_1_1")(input1)
conv_1_2 = Conv1D(filters = 32, kernel_size = (1,6) , padding = "same" , activation = "relu" , name = "conv_1d_1_1")(input2)

...

是否可以在for的某些keras循环中执行此操作?

1 个答案:

答案 0 :(得分:2)

inputs_list = [Input(shape=(1,78,3)) for i in range(72)]
conv_1_list = [Conv1D(filters = 32, kernel_size = (1,6) , padding = "same" , activation = "relu" , name = "conv_1d_1_0")(input_tensor) for input_tensor in inputs_list]

这有用吗? : - )