Siamese Network — Unofficial Keras Implementation [Paper]
- Large number of images of each class required for training.
- Cannot expect to test another class images with the network trained on the specified classes.
- Network must be “re-trained” if class(es) with many images are added.�
- When the total number of classes are huge
- When the number of classes is dynamically changing
- When it’s difficult to collect the images of a class
- When the cost of data collection and periodical re-training is too high
[Examples] face recognition, signature recognition, item identification in retail, etc.
- Our brain doesn’t need thousands of pictures of the same object in order to be able to identify it.
- Only one training example for each class required (That’s why the training is called “One Shot”.)
- Siamese networks are a special type of neural network architecture which learns to differentiate between two inputs instead of learns to classify them.
Using google_images_download Python library some celeb faces are collected (data-downloading.py).
Faces were extracted using MTCNN (face-extraction.py).
Some faces are missing or unwanted faces are found from the downloaded images via google_images_download library.
The selection of the faces are done manually by checking the images one after another.
- The image on the left is download with the keyword “Chen YenXi”, but the extracted face on the right is not her face.
- So I selected the 20 images per person with wanted faces extracted from the 50 downloaded images.
Selected images (faces) were converted to grayscale (convert-to-gray.py).
(siamese-nework-face-data-preparation.py)
similar pairs and dissimilar pairs dataset are randomly chosen and saved as numpy data format.
(siamese-nework-face-train.py)
- Base network
- Distance measure (Euclidian distance)
- Loss(cost) function: Contrastive Loss
You can find an article about "Good explanations on Ranking Loss" in here.
(siamese-nework-face-prediction.py)
Firstly, a reference(anchor) image is chosen and feed-forwarded through the trained Siamese network to get the embedding(feature) vector - featVec_1.
Next, an image per the category is chosen and feed-forwarded through the trained Siamese network to get the embedding(feature) vector - featVec_i, i = 1, ..., N where N is the number of categories.
Next, find i such that the distance of featVec_i from featVec_1 is minimum and then i is the category the reference(anchor) belongs to.
(app.py)
Try to test in your web browser using the Flask app!













