Distance-Ratio-Based Formulation for Metric Learning

Overview

Distance-Ratio-Based Formulation for Metric Learning

Environment

Preparing datasets

CUB

  • Change directory to /filelists/CUB
  • run source ./download_CUB.sh

One might need to manually download CUB data from http://www.vision.caltech.edu/visipedia-data/CUB-200-2011/CUB_200_2011.tgz.

mini-ImageNet

  • Change directory to /filelists/miniImagenet
  • run source ./download_miniImagenet.sh (WARNING: This would download the 155G ImageNet dataset.)

To only download 'miniImageNet dataset' and not the whole 155G ImageNet dataset:

(Download 'csv' files from the codes in /filelists/miniImagenet/download_miniImagenet.sh. Then, do the following.)

First, download zip file from https://drive.google.com/file/d/0B3Irx3uQNoBMQ1FlNXJsZUdYWEE/view (It is from https://github.com/oscarknagg/few-shot). After unzipping the zip file at /filelists/miniImagenet, run a script /filelists/miniImagenet/prepare_mini_imagenet.py which is modified from https://github.com/oscarknagg/few-shot/blob/master/scripts/prepare_mini_imagenet.py. Then, run /filelists/miniImagenet/write_miniImagenet_filelist2.py.

Train

Run python ./train.py --dataset [DATASETNAME] --model [BACKBONENAME] --method [METHODNAME] --train_aug [--OPTIONARG]

To also save training analyses results, for example, run python ./train.py --dataset miniImagenet --model Conv4 --method protonet_S --train_aug --n_shot 5 --train_n_way 5 --test_n_way 5 > record/miniImagenet_Conv4_proto_S_5s5w.txt

train_models.ipynb contains codes for our experiments.

Save features

Save the extracted feature before the classifaction layer to increase test speed.

For instance, run python ./save_features.py --dataset miniImagenet --model Conv4 --method protonet_S --train_aug --n_shot 5 --train_n_way 5

Test

For example, run python ./test.py --dataset miniImagenet --model Conv4 --method protonet_S --train_aug --n_shot 5 --train_n_way 5 --test_n_way 5

Analyze training

Run /record/analyze_training_1shot.ipynb and /record/analyze_training_5shot.ipynb to analyze training results (norm ratio, con-alpha ratio, div-alpha ratio, and con-div ratio)

Results

The test results will be recorded in ./record/results.txt

Visual comparison of softmax-based and distance-ratio-based (DR) formulation

The following images visualize confidence scores of red class when the three points are the representing points of red, green, and blue classes.

Softmax-based formulation DR formulation

References and licence

Our repository (a set of codes) is forked from an original repository (https://github.com/wyharveychen/CloserLookFewShot) and codes are under the same licence (LICENSE.txt) as the original repository except for the following.

/filelists/miniImagenet/prepare_mini_imagenet.py file is modifed from https://github.com/oscarknagg/few-shot. It is under a different licence in /filelists/miniImagenet/prepare_mini_imagenet.LICENSE

Copyright and licence notes (including the copyright note in /data/additional_transforms.py) are from the original repositories (https://github.com/wyharveychen/CloserLookFewShot and https://github.com/oscarknagg/few-shot).

Modifications

List of modified or added files (or folders) compared to the original repository (https://github.com/wyharveychen/CloserLookFewShot):

io_utils.py backbone.py configs.py train.py save_features.py test.py utils.py README.md train_models.ipynb /methods/__init__.py /methods/protonet_S.py /methods/meta_template.py /methods/protonet_DR.py /methods/softmax_1nn.py /methods/DR_1nn.py /models/ /filelists/miniImagenet/prepare_mini_imagenet.py /filelists/miniImagenet/prepare_mini_imagenet.LICENSE /filelists/miniImagenet/write_miniImagenet_filelist2.py /record/ /record/preprocessed/ /record/analyze_training_1shot.ipynb /record/analyze_training_5shot.ipynb

My (Hyeongji Kim) main contributions (modifications) are in /methods/meta_template.py, /methods/protonet_DR.py, /methods/softmax_1nn.py, /methods/DR_1nn.py, /record/analyze_training_1shot.ipynb, and /record/analyze_training_5shot.ipynb.

You might also like...
Dogs classification with Deep Metric Learning using some popular losses
Dogs classification with Deep Metric Learning using some popular losses

Tsinghua Dogs classification with Deep Metric Learning 1. Introduction Tsinghua Dogs dataset Tsinghua Dogs is a fine-grained classification dataset fo

Code reproduce for paper
Code reproduce for paper "Vehicle Re-identification with Viewpoint-aware Metric Learning"

VANET Code reproduce for paper "Vehicle Re-identification with Viewpoint-aware Metric Learning" Introduction This is the implementation of article VAN

Official PyTorch Implementation of Embedding Transfer with Label Relaxation for Improved Metric Learning, CVPR 2021
Official PyTorch Implementation of Embedding Transfer with Label Relaxation for Improved Metric Learning, CVPR 2021

Embedding Transfer with Label Relaxation for Improved Metric Learning Official PyTorch implementation of CVPR 2021 paper Embedding Transfer with Label

Towards Interpretable Deep Metric Learning with Structural Matching
Towards Interpretable Deep Metric Learning with Structural Matching

DIML Created by Wenliang Zhao*, Yongming Rao*, Ziyi Wang, Jiwen Lu, Jie Zhou This repository contains PyTorch implementation for paper Towards Interpr

[ICCV 2021] Official PyTorch implementation for Deep Relational Metric Learning.
[ICCV 2021] Official PyTorch implementation for Deep Relational Metric Learning.

Deep Relational Metric Learning This repository is the official PyTorch implementation of Deep Relational Metric Learning. Framework Datasets CUB-200-

GeDML is an easy-to-use generalized deep metric learning library
GeDML is an easy-to-use generalized deep metric learning library

GeDML is an easy-to-use generalized deep metric learning library

A Pytorch implementation of
A Pytorch implementation of "Manifold Matching via Deep Metric Learning for Generative Modeling" (ICCV 2021)

Manifold Matching via Deep Metric Learning for Generative Modeling A Pytorch implementation of "Manifold Matching via Deep Metric Learning for Generat

Unofficial implementation of Proxy Anchor Loss for Deep Metric Learning
Unofficial implementation of Proxy Anchor Loss for Deep Metric Learning

Proxy Anchor Loss for Deep Metric Learning Unofficial pytorch, tensorflow and mxnet implementations of Proxy Anchor Loss for Deep Metric Learning. Not

Paper: Cross-View Kernel Similarity Metric Learning Using Pairwise Constraints for Person Re-identification

Cross-View Kernel Similarity Metric Learning Using Pairwise Constraints for Person Re-identification T M Feroz Ali, Subhasis Chaudhuri, ICVGIP-20-21

Owner
Hyeongji Kim
Hyeongji Kim
Python implementation of the multistate Bennett acceptance ratio (MBAR)

pymbar Python implementation of the multistate Bennett acceptance ratio (MBAR) method for estimating expectations and free energy differences from equ

Chodera lab // Memorial Sloan Kettering Cancer Center 169 Dec 2, 2022
Automatically measure the facial Width-To-Height ratio and get facial analysis results provided by Microsoft Azure

fwhr-calc-website This project is to automatically measure the facial Width-To-Height ratio and get facial analysis results provided by Microsoft Azur

SoohyunPark 1 Feb 7, 2022
TSDF++: A Multi-Object Formulation for Dynamic Object Tracking and Reconstruction

TSDF++: A Multi-Object Formulation for Dynamic Object Tracking and Reconstruction TSDF++ is a novel multi-object TSDF formulation that can encode mult

ETHZ ASL 130 Dec 29, 2022
Neural-Pull: Learning Signed Distance Functions from Point Clouds by Learning to Pull Space onto Surfaces(ICML 2021)

Neural-Pull: Learning Signed Distance Functions from Point Clouds by Learning to Pull Space onto Surfaces(ICML 2021) This repository contains the code

null 149 Dec 15, 2022
Official PyTorch implementation of "Proxy Synthesis: Learning with Synthetic Classes for Deep Metric Learning" (AAAI 2021)

Proxy Synthesis: Learning with Synthetic Classes for Deep Metric Learning Official PyTorch implementation of "Proxy Synthesis: Learning with Synthetic

NAVER/LINE Vision 30 Dec 6, 2022
Effect of Different Encodings and Distance Functions on Quantum Instance-based Classifiers

Effect of Different Encodings and Distance Functions on Quantum Instance-based Classifiers The repository contains the code to reproduce the experimen

Alessandro Berti 4 Aug 24, 2022
Official implementation of "MetaSDF: Meta-learning Signed Distance Functions"

MetaSDF: Meta-learning Signed Distance Functions Project Page | Paper | Data Vincent Sitzmann*, Eric Ryan Chan*, Richard Tucker, Noah Snavely Gordon W

Vincent Sitzmann 100 Jan 1, 2023
A-SDF: Learning Disentangled Signed Distance Functions for Articulated Shape Representation (ICCV 2021)

A-SDF: Learning Disentangled Signed Distance Functions for Articulated Shape Representation (ICCV 2021) This repository contains the official implemen

null 81 Dec 14, 2022
Learning Continuous Signed Distance Functions for Shape Representation

DeepSDF This is an implementation of the CVPR '19 paper "DeepSDF: Learning Continuous Signed Distance Functions for Shape Representation" by Park et a

Meta Research 1.1k Jan 1, 2023
Metric learning algorithms in Python

metric-learn: Metric Learning in Python metric-learn contains efficient Python implementations of several popular supervised and weakly-supervised met

null 1.3k Dec 28, 2022