我正在尝试将Keras的连体层与共享的
在代码中,我有类似以下内容的东西:
Convolution2D
层结合使用。在Siamese
层之前,我不需要输入通过任何其他层,但是Siamese
层要求指定输入层。我无法想出如何创建与卷积层输入匹配的输入层。我能找到的唯一一个具体的Siamese
层示例是在测试中,其中使用Dense
层(带有向量输入)作为输入。基本上,我想要一个输入层,允许我将图像尺寸指定为输入,以便它们可以传递给共享的卷积层。在代码中,我有类似以下内容的东西:
img_rows = 28
img_cols = 28
img_input_shape = (1, img_rows, img_cols)
shared = Sequential()
shared.add(Convolution2D(nb_filters, nb_conv, nb_conv,
border_mode='valid',
input_shape=img_input_shape))
shared.add(Activation('relu'))
# .... more layers, etc.
right_input_layer = SomeInputLayer(input_shape=img_input_shape) # what should SomeInputLayer be?
left_input_layer = SomeInputLayer(input_shape=img_input_shape)
siamese = Siamese(shared, [left_input_layer, right_input_layer], merge_mode='concat')
model = Sequential()
model.add(siamese)
# ...
model.compile(loss=contrastive_loss, optimizer='rmsprop')
“SomeInputLayer”应该是什么?或者说我的方法一般来说是错误的吗?
Graph
API 更加直观易用。我已经将这样一个网络添加到了 Keras 的示例中此处。 - Mikael Roussonadd_node
部分输出2个输出(2个成对距离)。 - entropiece