Skip to content

AminNasiri63/Siamese-Triplet-Image-Similarity

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

28 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🧠 Image Similarity Estimation using Siamese Network with Triplet Loss

Overview

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.

Key Features

βœ… 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.

Data Structure

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.

Installation

Make sure you have Python 3.7+ and the following packages installed:

pip install tensorflow seaborn matplotlib numpy pandas

Usage

  • 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.

Project Structure

  • SiameseNetwork.ipynb: Jupyter notebook containing the full pipeline (data loading, training, evaluation)

References

License

MIT License

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published