How to model a Siamese Network?
which is usefull to solve a two classification problems.
[8] S. Chopra, R. Hadsell, and Y. LeCun. Learning a similarity metric discriminatively, with application to face verification. In CVPR, 2005. 2, 5
Which two?
@kloudkl two-classification (same or not same). input two image, output a bool value(1/0). layes except the top layer whill be replicated twice.
reference from the "deepface paper": once learned, the face recognition network (without the top layer) is replicated twice (one for each input image) and the features are used to directly predict whether the two input images belong to the same person. This is accomplished by: a) taking the absolute difference between the features, followed by b) a top fully connected layer that maps into a single unit(same/not same).
Siamese nets are supervised models for metric learning [1].
[1] S. Chopra, R. Hadsell, and Y. LeCun. Learning a similarity metric discriminatively, with application to face verification. In Computer Vision and Pattern Recognition, 2005. CVPR 2005. IEEE Computer Society Conference on, volume 1, pages 539–546. IEEE, 2005. http://yann.lecun.com/exdb/publis/pdf/chopra-05.pdf
Speaking of metric learning, I remember that @norouzi proposed and open sourced a method that learned a Hamming distance metric to distinguish similar and dissimilar images [2].
[2] Mohammad Norouzi, David J. Fleet, Ruslan Salakhutdinov, Hamming Distance Metric Learning, Neural Information Processing Systems (NIPS), 2012.
@kloudkl Thanks! I'm wondering how to realize it using caffe.
Siamese nets require weight sharing so that a single set of parameters aggregate derivatives. This is an in-progress enhancement to Caffe.
I have implemented LeCun's face verification CNN in Caffe. I created two Caffe::Net NetA, NetB with the same config, instead of hacking in Caffe to share their weight, I first forward/backward NetA and NetB separately, then add NetB's gradients to NetA, update NetA, and copy NetA's parameters to NetB to keep them synchronized.
I think memcpy should be cheap compared to convolution, so the overhead should be relative small.
@chyh1990 Could you help - how do you calculate gradients for LeCun CNN? maybe you can share code snippet? I have difficulty implementing the same in other library (EBLearn). Thank you!
@chyh1990 Thank you, looking at it. 90% on which dataset? In one of the papers, regarding square: "Second, we must emphasize that using the square norm instead of the L1 norm for the energy would not be appropriate. Indeed, if the energy were the square norm of the difference between the output vectors of the two patterns, the gradient of the energy with respect to the parameter would vanish as the energy approached zero. This would create a dangerous plateau in the loss function. This could lead to failure of the machine to learn in cases where the two images are impostors and the corresponding energy is near zero."
@okn2020 We use our own unpublished dataset. It seems I should modify my loss function.
@chyh1990 Hi, I have tried running your implementation on a relatively simple database with 100k and 1M examples (half negative half positive) 50x58 and your network config, and it does not seem to work. If I analyze ROC and find best separation threshold between positive and negative samples, I see it reaches 65% after few epochs but then falling to 52-55. I have tried other loss functions, they seem to behave similar. Do I miss something?
@chyh1990 I have also tried setting learning rate to 0.01 and reducing number of output on feature layer 8192->4096, it get a bit better, but not reaches more than 67%
@chyh1990 I am running Caffe, 'ver' branch on Windows, GPU mode. I have only extended accuracy layer a bit to see exact output of network...
Weight sharing was done in #500. Please follow up with further siamese network discussion in #697.
Hello, I am very new in the Siamese Network and is trying to use it for face recognition of my own data sets. (28 classes with 1333 images). I edited the mnist_siamese_train_test.prototxt file in my own way and tried to train the model but everytime it is showing the error which is as: net.cpp:453] Check failed: this_blob->channels() == owner_blob->channels() (2 vs. 1) Shared parameter blobs must have the same channels.
Is this could be related as the problem with my dataset preparation??
The training data in the dataset must have 2 channels, each channel is used to store one image.
Hi Does anyone tried to do siamese data preparation based on image list format (img1 img2 label) ?
@sunbaigui hi,Have you solved the problem? I also want to know how write the image list file, did it work like this format (img1 img2 label) ? How did you do?
@anxiaoxi45 I havn't done this yet, sorry for reply so late, kind of busy recently, have you done it yet?
@anxiaoxi45 @sunbaigui Have you solved the (img1 img2 label) problem?