All Projects → ahmdtaha → tf_retrieval_baseline

ahmdtaha / tf_retrieval_baseline

Licence: Apache-2.0 license
A Tensorflow retrieval (space embedding) baseline. Metric learning baseline on CUB and Stanford Online Products.

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to tf retrieval baseline

GLOM-TensorFlow
An attempt at the implementation of GLOM, Geoffrey Hinton's paper for emergent part-whole hierarchies from data
Stars: ✭ 32 (-17.95%)
Mutual labels:  embedding, tensorflow2
CVPR2020 PADS
(CVPR 2020) This repo contains code for "PADS: Policy-Adapted Sampling for Visual Similarity Learning", which proposes learnable triplet mining with Reinforcement Learning.
Stars: ✭ 57 (+46.15%)
Mutual labels:  retrieval, metric-learning
MHCLN
Deep Metric and Hash Code Learning Network for Content Based Retrieval of Remote Sensing Images
Stars: ✭ 30 (-23.08%)
Mutual labels:  retrieval, metric-learning
DREML
PyTorch implementation of Deep Randomized Ensembles for Metric Learning(ECCV2018)
Stars: ✭ 67 (+71.79%)
Mutual labels:  embedding, retrieving-images
point-cloud-segmentation
TF2 implementation of PointNet for segmenting point clouds
Stars: ✭ 33 (-15.38%)
Mutual labels:  tensorflow2
awesome-visual-localization-papers
The relocalization task aims to estimate the 6-DoF pose of a novel (unseen) frame in the coordinate system given by the prior model of the world.
Stars: ✭ 60 (+53.85%)
Mutual labels:  retrieval
gans-2.0
Generative Adversarial Networks in TensorFlow 2.0
Stars: ✭ 76 (+94.87%)
Mutual labels:  tensorflow2
plexus
Plexus - Interactive Emotion Visualization based on Social Media
Stars: ✭ 27 (-30.77%)
Mutual labels:  retrieval
OpenANE
OpenANE: the first Open source framework specialized in Attributed Network Embedding. The related paper was accepted by Neurocomputing. https://doi.org/10.1016/j.neucom.2020.05.080
Stars: ✭ 39 (+0%)
Mutual labels:  embedding
triplet-loss-pytorch
Highly efficient PyTorch version of the Semi-hard Triplet loss ⚡️
Stars: ✭ 79 (+102.56%)
Mutual labels:  metric-learning
GPQ
Generalized Product Quantization Network For Semi-supervised Image Retrieval - CVPR 2020
Stars: ✭ 60 (+53.85%)
Mutual labels:  metric-learning
potato-disease-classification
Potato Disease Classification - Training, Rest APIs, and Frontend to test.
Stars: ✭ 95 (+143.59%)
Mutual labels:  tensorflow2
doctr
docTR (Document Text Recognition) - a seamless, high-performing & accessible library for OCR-related tasks powered by Deep Learning.
Stars: ✭ 1,409 (+3512.82%)
Mutual labels:  tensorflow2
Bearcat captcha
熊猫识别不定长验证码,基于tensorflow2.2(tensorflow2.3也可以运行)轻松就能练出不错的模型
Stars: ✭ 67 (+71.79%)
Mutual labels:  tensorflow2
tf-image
TensorFlow2+ graph image augmentation library optimized for tf.data.Dataset.
Stars: ✭ 24 (-38.46%)
Mutual labels:  tensorflow2
visual-compatibility
Context-Aware Visual Compatibility Prediction (https://arxiv.org/abs/1902.03646)
Stars: ✭ 92 (+135.9%)
Mutual labels:  metric-learning
cineast
Cineast is a multi-feature content-based mulitmedia retrieval engine. It is capable of retrieving images, audio- and video sequences as well as 3d models based on edge or color sketches, textual descriptions and example objects.
Stars: ✭ 51 (+30.77%)
Mutual labels:  retrieval
golang-tf
Working golang + tensorflow
Stars: ✭ 21 (-46.15%)
Mutual labels:  tensorflow2
shrec17
Supplementary code for SHREC 2017 RGB-D Object-to-CAD Retrieval track
Stars: ✭ 27 (-30.77%)
Mutual labels:  retrieval
Adaptive-Gradient-Clipping
Minimal implementation of adaptive gradient clipping (https://arxiv.org/abs/2102.06171) in TensorFlow 2.
Stars: ✭ 74 (+89.74%)
Mutual labels:  tensorflow2

Tensorflow Retrieval Baseline

This repository provides a retrieval/space embedding baseline using multiple retrieval datasets and ranking losses. This code is based on triplet-reid repos.

Evaluation Metrics

  1. Normalized Mutual Information (NMI)
  2. Recall@K

Deep Fashion In-shop Retrieval Evaluation

All the following experiments assume a training mini-batch of size 60. The architecture employed is the one used in In Defense of the Triplet Loss for Person Re-Identification but ResNet is replaced by a DenseNet169. Optimizer: Adam, Number of iterations = 25K

Method Normalized Margin NMI R@1 R@4 # of classes #samples per class
Semi-Hard Yes 0.2 0.902 87.43 95.42 10 6
Hard-Negative No 1.0 0.904 88.38 95.74 10 6
Lifted Structured No 1.0 0.903 87.32 95.59 10 6
N-Pair Loss No N/A 0.903 89.12 96.13 30 2
Angular Loss Yes N/A 0.8931 84.70 92.32 30 2
Custom Contrastive Loss Yes 1.0 0.826 44.09 67.17 15 4

CUB200-2011 Retrieval Evaluation

Mini-batch size=120. Architecture: Inception_Net V1. Optimizer: Momentum. Number of iterations = 10K

Method Normalized Margin NMI R@1 R@4 # of classes #samples per class
Semi-Hard Yes 0.2 0.587 49.03 73.43 20 6
Hard Negatives No 1.0 0.561 46.55 71.03 20 6
Lifted Structured No 1.0 0.502 35.26 59.82 20 6
N-Pair Loss No N/A 0.573 46.52 59.26 60 2
Angular Loss Yes N/A 0.546 45.50 68.43 60 2
Custom Contrastive Loss Yes 1.0 0.476 37.27 62.39 30 4

Stanford Online Products Retrieval Evaluation

Mini-batch size=120. Architecture: Inception_Net V1. Optimizer: Adam. Number of iterations = 30K

Method Normalized Margin NMI R@1 R@4 # of classes #samples per class
Semi-Hard Yes 0.2 0.893 71.22 81.77 20 6
Hard Negatives No 1.0 0.895 72.03 82.55 20 6
Lifted Structured No 1.0 0.889 68.26 79.72 20 6
N-Pair Loss No N/A 0.893 72.60 82.59 60 2
Angular Loss Yes N/A 0.878 60.30 72.78 60 2
Custom Contrastive Loss Yes 1.0 0.825 19.05 32.28 30 4

Requirements

  • Python 3+ [Tested on 3.4.7 / 3.7]
  • Tensorflow 1 and TF 2.0 [Tested on 1.8 / 1.14 / 2.0]

Code Setup

  1. Update the directories' paths in constants.py.
  2. Use train.py and train_tf2.py for TF 1.X and TF 2.X, respectively.
  3. Use embed.py and embed_tf2.py for TF 1.X and TF 2.X, respectively.
  4. eval.py.

Supported Ranking losses

  • Triplet Loss with hard mining - 'hard_triplet'
  • Triplet Loss with semi-hard mining - 'semi_hard_triplet'
  • Lifted Structure Loss - 'lifted_loss'
  • N-pairs loss - 'npairs_loss'
  • Angular loss - 'angular_loss'
  • Contrastive loss - 'contrastive_loss'

Keep an eye on ranking/__init__.py for new ranking loss

Recommeneded Setting for each loss

Method Setting
Semi-Hard L2-Norm Yes, Margin =0.2
Hard Negatives L2-Norm No , Margin =1.0
Lifted Structured L2-Norm No , Margin =1.0
N-Pair Loss L2-Norm No , Margin =N/A
Angular Loss L2-Norm Yes, Margin =N/A
Custom Contrastive Loss L2-Norm Yes, Margin =1.0

Wiki

  • [Done] Explain the fast contrastive loss sampling procedure
  • [Done] The contrastive loss in the repos is customized to avoid nan during training. When the anchor and positive belong to the same class and the distance between their embeddings is near zero, the derivative turns into nan. Lei Mao provides a nice detailed mathematical explanation for this issue.

TODO

  • [TODO] bash script for train, embed and then eval
  • [TODO] Evaluate space embedding during training.
  • [TODO] After supporting TF 2.0 (eager execution), It become easier to support more losses -- Maybe add Margin loss.

Misc Notes

  • I noticed that some methods depend heavily on training parameters like the optimizer and number of iterations. For example, the semi-hard negative performance drops significantly on CUB-dataset if Adam optimizer is used instead of Momentum! The number of iterations seems also matter for this small dataset.
  • The Tensorflow 2.0 implementation uses more memory even when disabling the eager execution. I tested the code with a smaller batch size -- ten classes and five samples per class. After training for 10K iterations, the performance achieved is NMI=0.54, R@1=42.64, R@4=66.52.

Release History

  • 0.0.1
    • CHANGE: Jan 8, 2020. Update code to support Tensorflow 2.0
    • CHANGE: Dec 31, 2019. Update code to support Tensorflow 1.14
    • First Commit: May 24, 2019. Code tested on Tensorflow 1.8
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].