Skip to content

Implementation of a Siamese Neural Network (in Tensorflow) that defines a similarity score between a pair of person images.

Notifications You must be signed in to change notification settings

FrancoisMasson1990/Siamese_Network

Repository files navigation

Metric Learning for Person Re-identification

Implementation of a Siamese Neural Network (in Tensorflow) that defines a similarity score between a pair of person images.

Installation

pip3 install -r requirements.txt

Preprocess Dataset

Download the MARS dataset from here:

  • The link contains both training and test set in a zip format. Extract both and create some directories first: THE TWO FOLDERS should be named training_dataset and testing_dataset !!
└── MARS_DATASET_ROOT
       ├── training_dataset    
       |   ├── 0001
       |        ....jpg
       |        ....jpg
       |
       └── testing_dataset     
           ├── 0000 
                ....jpg
                ....jpg

Create a training and validation set for your dataset: (This is done by generating a TFRecord file for TensorFlow consumption)

python3 create_tf_record.py --tfrecord_filename=mars --dataset_dir=/path/to/MARS_DATASET_ROOT

Training the Siamese Network

Creates a TFRecord file and then train the model on the generated TFRecord file :

python3 train_net.py /path/to/train_dataset/

Using TensorBoard, you can see the updates (There are also stored in ./train.log/).

In a terminal (Ubuntu user) run :

tensorboard --logdir /path/to/train.log/

Testing the Siamese Network

python3 test_net.py /image_1_path /image_2_path

This will output a similiraty score between the two images

Results and Improvements

The possibilities to improve the results :

  • Using transfer learning : a pre-trained model such as VGG19 instead of training from scratch

Transfer learning in Tensorflow without using Keras can be done with tensornets :

pip install git+https://github.com/taehoonlee/tensornets.git

Then used for example VGG19 pretrained model :

python3 train_net.py /path/to/train_dataset/ --transfer_learning=True
python3 train_net.py /path/to/train_dataset/ --contrastive=True
  • Combine transfer learning and constrastive loss :
python3 train_net.py /path/to/train_dataset/ --transfer_learning=True --contrastive=True
  • Play with the hyper-parameters : adding dropout, learning rate,...
  • Data augmentation

First implementation :

A first attempt containing the pre-trained model weights can be downloaded via :

Extract and place the folder in the same level as test_net.py (keep the folder's name /model_siamese)

About

Implementation of a Siamese Neural Network (in Tensorflow) that defines a similarity score between a pair of person images.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages