Keras:如何将两层而不是元素组合成更大的形状
Keras: How to Combine two Layers, but not Elementwise, into bigger shape
所以我想在我的 keras-nn 中将多个图层合并为 1 个图层。不同之处在于,我不想像 Add()
层那样组合它们,但我想将具有不同形状但相同维度的多个层组合成一个更大的层,其形状是输入层。这是我粗略画的结构(圆点代表一个节点):
下面是一些我想象中的代码:
[IN]
input_1 = Input(shape=(4,))
input_2 = Input(shape=(6,))
combined = Combined()([input_1, input_2])
print(input_1.shape, input_2.shape, input_3.shape)
[OUT]
(4,) (6,) (10,)
keras中可能已经有一个Layer具备了这个功能,但是我在网上浏览了一段时间,没有找到解决这个问题的方法
~奥卡加纳
你要的是Concatenate
层:
input_1 = Input(shape=(4,))
input_2 = Input(shape=(6,))
combined = Concatenate()([input_1, input_2])
print(input_1.shape, input_2.shape, combined.shape)
这输出:
(?, 4) (?, 6) (?, 10)
所以我想在我的 keras-nn 中将多个图层合并为 1 个图层。不同之处在于,我不想像 Add()
层那样组合它们,但我想将具有不同形状但相同维度的多个层组合成一个更大的层,其形状是输入层。这是我粗略画的结构(圆点代表一个节点):
下面是一些我想象中的代码:
[IN]
input_1 = Input(shape=(4,))
input_2 = Input(shape=(6,))
combined = Combined()([input_1, input_2])
print(input_1.shape, input_2.shape, input_3.shape)
[OUT]
(4,) (6,) (10,)
keras中可能已经有一个Layer具备了这个功能,但是我在网上浏览了一段时间,没有找到解决这个问题的方法
~奥卡加纳
你要的是Concatenate
层:
input_1 = Input(shape=(4,))
input_2 = Input(shape=(6,))
combined = Concatenate()([input_1, input_2])
print(input_1.shape, input_2.shape, combined.shape)
这输出:
(?, 4) (?, 6) (?, 10)