Siamese Net BackProp, how to effectively update?

148 views Asked by At

How to most effectively update the shared weights of a Siamese Net, given contrastive loss function in Tensorflow?

1

There are 1 answers

0
chris On BEST ANSWER

Abstract the network that produces the embeddings into a function. Just call the function twice - once for each image you pass in. It's referred to as two networks... that seems like an overstatement to me. It's just that you pass it through the same network. You'll want to reuse variables in between the two function calls. My code looks something like this:

def pipeline(images, reuse):
  with tf.variable_scope('pipeline', reuse=reuse) as scope:
  # ... conv layers etc. That produce the embedding.

output_a = pipeline(a_images, False)
output_b = pipeline(b_images, True)