项目作者: avilash

项目描述 :
One-Shot Learning with Triplet CNNs in Pytorch
高级语言: Python
项目地址: git://github.com/avilash/pytorch-siamese-triplet.git
创建时间: 2018-11-06T07:12:38Z
项目社区:https://github.com/avilash/pytorch-siamese-triplet

开源协议:

下载


Deep metric learning using Triplet network in PyTorch

The following repository contains code for training Triplet Network in Pytorch
Siamese and Triplet networks make use of a similarity metric with the aim of bringing similar images closer in the embedding space while separating non similar ones.
Popular uses of such networks being -

  • Face Verification / Classification
  • Learning deep embeddings for other tasks like classification / detection / segmentation

Paper - Deep metric learning using Triplet network

Installation

Install PyTorch

  1. pip install -r requirements.txt

Demo

Colab notebook with pretrained weights

Training

  1. python train.py --cuda

This by default will train on the MNIST dataset

MNIST / FashionMNIST

  1. python train.py --result_dir results --exp_name MNIST_exp1 --cuda --dataset <manist>/<fmnist>

To create a tSNE visualisation

  1. python tsne.py --ckp <path to model>

The embeddings and the labels are stored in the experiment folder as a pickle file, and you do not have to run the model everytime you create a visualisation. Just pass the saved embeddings as the —pkl parameter

  1. python tsne.py --pkl <path to stored embeddings>

Sample tSNE visualisation on MNIST
tSNE

VGGFace2

Specify the location of the dataset in test.yaml
The directory should have the following structure

  1. +-- root
  2. | +-- train
  3. | +-- class1
  4. | +-- img1.jpg
  5. | +-- img2.jpg
  6. | +-- img3.jpg
  7. | +-- class2
  8. | +-- class3
  9. | +-- test
  10. | +-- class4
  11. | +-- class5
  1. python train.py --result_dir results --exp_name VGGFace2_exp1 --cuda --epochs 50 --ckp_freq 5 --dataset vggface2 --num_train_samples 32000 --num_test_samples 5000 --train_log_step 50

Custom Dataset

Specify the location of the dataset in test.yaml
The directory should have the following structure

  1. +-- root
  2. | +-- train
  3. | +-- class1
  4. | +-- img1.jpg
  5. | +-- img2.jpg
  6. | +-- img3.jpg
  7. | +-- class2
  8. | +-- class3
  9. | +-- test
  10. | +-- class4
  11. | +-- class5
  1. python train.py --result_dir results --exp_name Custom_exp1 --cuda --epochs 50 --ckp_freq 5 --dataset custom --num_train_samples 32000 --num_test_samples 5000 --train_log_step 50

TODO

  • Train on MNIST / FashionMNIST
  • Train on a public dataset
  • Multi GPU Training
  • Custom Dataset
  • Include popular models - ResneXT / Resnet / VGG / Inception