r/computervision • • Sep 15 '26

Discussion Tried using a Siamese Network for a small computer vision problem

I've been experimenting with one-shot learning and wanted to try something other than a standard classifier.

The problem is pretty simple: classify images as front view vs top view.

I trained a Siamese network where two images go through the same encoder, and the model learns whether their embeddings should be close or far apart using contrastive loss.

So instead of directly asking:

"Is this a front view image?"

the idea is more like:

"Is this image more similar to my front view reference or my top view reference?"

It was interesting to see how changing the problem from classification to similarity/metric learning changes the whole approach.

I'm still experimenting with it, so I'm curious what others would do for a problem like this.

Would you use a Siamese network, a regular classifier, pre trained embeddings + cosine similarity, or something else?

4 Upvotes

17 comments sorted by

3

u/Dry-Snow5154 Sep 15 '26

Isn't Siamese net at least 2x slower than a regular classifier for this problem? And also same accuracy at best. Why would you want to use one?

You can also train a regression model which outputs 0-100 range for top-to-front. But again, why do that? Or why use embeddings for binary classification problem?

Every model type has a use case. You can always shave a square peg into a round hole if you try hard enough. But why would you want to?

3

u/bfyvfftujijg Sep 15 '26

All of this.

It’s a fun experiment but for practical purposes just use a classifier.

1

u/Spiritual_Bit8891 Sep 15 '26

Problem is dataset, unable to find dataset for my use case.

1

u/bfyvfftujijg Sep 15 '26

Gotcha.

So you can get pairs of photos of the same thing

1

u/Spiritual_Bit8891 Sep 15 '26

Problem is dataset. Also, if I quantize the model, the inference time is reduced by a lot and saves me from the dataset problem too!

1

u/Dry-Snow5154 Sep 15 '26

How did Siamese net help you with the dataset, if it still needs correct labels to train? I don't follow.

1

u/Spiritual_Bit8891 Sep 15 '26

It just need two reference image for this problem one with front view and one top view. Not big dataset of similar image to train a classifier, just image is all you need.

1

u/Dry-Snow5154 Sep 15 '26

Wait, you don't even train your Siamese network? You take a random pre-trained one? Then how do you know it is even doing the right thing?

It might be comparing by any random criteria. Instead of "view" it could be "shape", or "color", or even "same animal", or just random guessing. Your accuracy could be 50% and without a proper val set you won't even know.

I'm afraid this is not a valid method to classify images.

Same with embeddings, if you don't train your encoder and take a random one it can be encoding anything but what you need. Might be encoding "catness" and you will never know.

1

u/unknownfolk Sep 15 '26

For a similar problem, we employed a standard classifier and it worked pretty well. Would love to hear what performances do you get with Siamese Network.

1

u/Spiritual_Bit8891 Sep 15 '26

It worked well when other attributes of object were same, I don't remember the exact metrics but failed when same object but with different attributes like colour, slight change in shape is present.

1

u/WeylLabs Sep 16 '26

We have an paper titled "Neural Phase Correlation" (arXiv:2606.18496) for these relational problems. We use it for correspondence/image registration/unitary dynamics, but it's an architecture for determining the transformation/relation between the content of two scenes. Not sure how well it would work for this, but could be applied after your Siamese networks.

1

u/Spiritual_Bit8891 Sep 17 '26

Sounds cool, will definitely try this one

2

u/ShadowxWarrior Sep 16 '26

If you are low on data you might want to try some pretrained embedder. You can turn pretty much any classifier into an embedder by removing the last layer from it. I would first try imagenet as a baseline test. If it's not good enough, you then try to find something which is more similar to your data, or you finetune it on your data a bit.

1

u/[deleted] Sep 15 '26

[removed] — view removed comment

2

u/Spiritual_Bit8891 Sep 15 '26

Two reference image and one query image. So instead of large dataset I just need 2 images for reference, then, compare query image with these 2 references.