Siamese Network

I created Siamese Network just like in the fastbook.
I trained this, so I want to predict labels for test images (there are near 15k images). I tried to calculate the similarity measure for one picture using a neural network based on pictures from the training sample (one picture for each label), but this calculation takes a very long time

so the question is: how can I make predictions quickly?

For large sets of comparisons, you can try to pre-calc, save, and reuse the activations for your ‘reference images’ from the known training set, then batch all the image-pairs up to use GPU during inferencing.

For example, you have known training images A, B, C, D, E… You pre-calc the activations so that you get tensors aA, aB, aC, aD, aE… Then for your test image 1, 2, 3, 4, 5… You will be generating image-pairs of 1-A, 1-B, 1-C… 2-A, 2-B, 2-C… etc., but you won’t need to recalc the activations for A,B,C… since you already have aA, aB, aC… which means that you only need to calculate the test set activations a1, a2, a3… Then for these large numbers of image-pairs you can batch up a1-aA, a1-aB, a1-aC… a2-aA, a2-aB, a2-aC… to feed into GPU and do your similarity calcs in batches there.

This article explains the concept pretty well.

Good luck!

Yijin

1 Like

How to create confusion matrix of siamese network in fastai.

Haven’t really thought about this much.

How would a confusion matrix look like for your usage of Siamese network? You’ve thought about it, so if you could describe / sketch out how you think it should work, I’m sure we can figure something out.

Yijin

Is there any way to visualise the difference or similarity activation map using gradcam in saimese network. How we can visualise the features in both images together.