This project implements a Siamese neural network trained using triplet loss for image similarity estimation. The model learns to embed images into a feature space where similar images are close together and dissimilar images are far apart. The model is built in TensorFlow/Keras and leverages distributed training across GPUs for faster convergence.
The project includes data handling, model creation, training with freezing and fine-tuning, and detailed evaluation metrics.
β
TensorFlow tf.data pipeline for efficient data loading.
β
Distributed training using tf.distribute.Strategy.
β
Modular and scalable training script.
β
Data pipeline using triplet generators.
β
Triplet loss function (anchor, positive, negative).
β
Progressive training (frozen backbone β fine-tuning).
β
Using transfer learning with ResNet50 for embeddings.
β
Comprehensive evaluation with confusion matrices and per-class metrics.
β
Visualization of training loss and evaluation results.
β
Easily adaptable for your own image datasets.
Your dataset directory should be organized as follows:
root_dataset_dir/
β
βββ ID_1/
β βββ image1.jpg
β βββ image2.jpg
β βββ ...
β
βββ ID_2/
β βββ image1.jpg
β βββ image2.jpg
β βββ ...
β
βββ ID_N/
βββ image1.jpg
βββ image2.jpg
βββ ...
- Each subfolder corresponds to one unique identity/class (
ID_1,ID_2, β¦). - Each subfolder contains multiple images of that identity.
- The code selects triplets (anchor, positive, negative) based on these folders.
Make sure you have Python 3.7+ and the following packages installed:
pip install tensorflow seaborn matplotlib numpy pandas
-
Prepare your dataset: Organize your image dataset as described above.
-
Configure paths and parameters: Edit the pathData variable and other parameters inside the notebook as needed.
-
Run training: Execute the training notebook to train the Siamese network.
-
Evaluate the model: Use the provided evaluation functions and cells to compute similarity metrics and visualize results.
- SiameseNetwork.ipynb: Jupyter notebook containing the full pipeline (data loading, training, evaluation)
- Keras Example: Siamese Network
- TensorFlow Guide: Distributed Training with Keras
- TensorFlow Guide: Distributed Training Overview
- Keras Guide: Transfer Learning & Fine-tuning
MIT License