Siamese drill network 220 in Keras

I am trying to use a Keras Siamese layer in combination with a common layer Convolution2D. I don’t need an input to go through other layers to a layer Siamese, but for a layer I Siameseneed to specify input layers. I can't figure out how to create input layers so that they match the conv level input. The only concrete example of the used layer Siamesethat I could find is in tests , where the Denselevels (with vector inputs) are used as input. Basically, I want the input level to allow me to specify image sizes as input so that they can be transferred to a common conv layer.

The code has something like the following:

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? ?

+4
1

, . "" Layer - , . , , Siamese (.. ), . , add_shared_layer.

, , , .

+3

Source: https://habr.com/ru/post/1627369/


All Articles