【发布时间】:2016-02-05 00:26:05
【问题描述】:
我正在尝试将 Keras 的 Siamese 层与共享的 Convolution2D 层结合使用。
我不需要输入在Siamese 层之前通过任何其他层,但Siamese 层需要指定输入层。我不知道如何创建输入层以匹配 conv 层的输入。我能找到使用Siamese 层的唯一具体示例是在tests 中,其中Dense 层(带有矢量输入)用作输入。基本上,我想要一个输入层,它允许我将图像尺寸指定为输入,以便它们可以传递到共享的 conv 层。
在代码中我有如下内容:
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 应该是什么?还是我的方法总体上不正确?
【问题讨论】:
标签: deep-learning conv-neural-network keras