7

I have Siamese network that produce feature maps for images, how do I get dot product of those feature maps with Keras?

input_a = Input(input_size)
input_b = Input(input_size)
fe_net_a = model(input_a)
fe_net_b = model(input_b)

E.g. if output tensor of fe_net_a and fe_net_b has shape (1, 17, 17, 1024), how to create layer that will produce tensor of shape (1, 17, 17), taking dot product of last axis?

DikobrAz
  • 3,557
  • 4
  • 35
  • 53

1 Answers1

0

From the keras documentation of the merge.Dot() function, is this what you are looking for?

from keras.layers import Input, dot

input_a = Input(input_size)
input_b = Input(input_size)
fe_net_a = model(input_a)
fe_net_b = model(input_b)

fe_ab = dot([fe_net_a,fe_net_b], axes = -1)

Does that work for you ?

Nassim Ben
  • 11,473
  • 1
  • 34
  • 52
  • 2
    Nope, it produces tensor of shape (1, 17, 17, 17). I'm new to Keras and deep learning, so I don't know why it's doing that. – DikobrAz Jun 08 '17 at 18:43
  • that doesn't make any sense. Please give us some reproducible code :) – Nassim Ben Jun 09 '17 at 07:32
  • 3
    ```>>> input_size=20, 10, 3 >>> input_a = Input(input_size) >>> input_b = Input(input_size) >>> fe_ab = dot([input_a, input_b], axes=-1) >>> fe_ab ``` – DikobrAz Jun 09 '17 at 16:48