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.

Owner
Hyeongji Kim
Hyeongji Kim
Official implementation of "Not only Look, but also Listen: Learning Multimodal Violence Detection under Weak Supervision" ECCV2020

XDVioDet Official implementation of "Not only Look, but also Listen: Learning Multimodal Violence Detection under Weak Supervision" ECCV2020. The proj

peng 64 Dec 12, 2022
SCI-AIDE : High-fidelity Few-shot Histopathology Image Synthesis for Rare Cancer Diagnosis

SCI-AIDE : High-fidelity Few-shot Histopathology Image Synthesis for Rare Cancer Diagnosis Pretrained Models In this work, we created synthetic tissue

Emirhan Kurtuluş 1 Feb 07, 2022
A Python package for faster, safer, and simpler ML processes

Bender 🤖 A Python package for faster, safer, and simpler ML processes. Why use bender? Bender will make your machine learning processes, faster, safe

Otovo 6 Dec 13, 2022
Real-time 3D multi-person detection made easy with OpenPose and the ZED

OpenPose ZED This sample show how to simply use the ZED with OpenPose, the deep learning framework that detects the skeleton from a single 2D image. T

blanktec 5 Nov 06, 2020
Pacman-AI - AI project designed by UC Berkeley. Designed reflex and minimax agents for the game Pacman.

Pacman AI Jussi Doherty CAP 4601 - Introduction to Artificial Intelligence - Fall 2020 Python version 3.0+ Source of this project This repo contains a

Jussi Doherty 1 Jan 03, 2022
Efficient Multi Collection Style Transfer Using GAN

Proposed a new model that can make style transfer from single style image, and allow to transfer into multiple different styles in a single model.

Zhaozheng Shen 2 Jan 15, 2022
PoseCamera is python based SDK for human pose estimation through RGB webcam.

PoseCamera PoseCamera is python based SDK for human pose estimation through RGB webcam. Install install posecamera package through pip pip install pos

WonderTree 7 Jul 20, 2021
Source code of SIGIR2021 Paper 'One Chatbot Per Person: Creating Personalized Chatbots based on Implicit Profiles'

DHAP Source code of SIGIR2021 Long Paper: One Chatbot Per Person: Creating Personalized Chatbots based on Implicit User Profiles . Preinstallation Fir

ZYMa 32 Dec 06, 2022
Automatic Number Plate Recognition using Contours and Convolution Neural Networks (CNN)

Cite our paper if you find this project useful https://www.ijariit.com/manuscripts/v7i4/V7I4-1139.pdf Abstract Image processing technology is used in

Adithya M 2 Jun 28, 2022
Source code for our paper "Learning to Break Deep Perceptual Hashing: The Use Case NeuralHash"

Learning to Break Deep Perceptual Hashing: The Use Case NeuralHash Abstract: Apple recently revealed its deep perceptual hashing system NeuralHash to

<a href=[email protected]"> 11 Dec 03, 2022
Provided is code that demonstrates the training and evaluation of the work presented in the paper: "On the Detection of Digital Face Manipulation" published in CVPR 2020.

FFD Source Code Provided is code that demonstrates the training and evaluation of the work presented in the paper: "On the Detection of Digital Face M

88 Nov 22, 2022
[ACM MM 2021] Yes, "Attention is All You Need", for Exemplar based Colorization

Transformer for Image Colorization This is an implemention for Yes, "Attention Is All You Need", for Exemplar based Colorization, and the current soft

Wang Yin 30 Dec 07, 2022
CLIPImageClassifier wraps clip image model from transformers

CLIPImageClassifier CLIPImageClassifier wraps clip image model from transformers. CLIPImageClassifier is initialized with the argument classes, these

Jina AI 6 Sep 12, 2022
CLNTM - Contrastive Learning for Neural Topic Model

Contrastive Learning for Neural Topic Model This repository contains the impleme

Thong Thanh Nguyen 25 Nov 24, 2022
Band-Adaptive Spectral-Spatial Feature Learning Neural Network for Hyperspectral Image Classification

Band-Adaptive Spectral-Spatial Feature Learning Neural Network for Hyperspectral Image Classification

258 Dec 29, 2022
A CNN implementation using only numpy. Supports multidimensional images, stride, etc.

A CNN implementation using only numpy. Supports multidimensional images, stride, etc. Speed up due to heavy use of slicing and mathematical simplification..

2 Nov 30, 2021
Code for the CIKM 2019 paper "DSANet: Dual Self-Attention Network for Multivariate Time Series Forecasting".

Dual Self-Attention Network for Multivariate Time Series Forecasting 20.10.26 Update: Due to the difficulty of installation and code maintenance cause

Kyon Huang 223 Dec 16, 2022
A basic implementation of Layer-wise Relevance Propagation (LRP) in PyTorch.

Layer-wise Relevance Propagation (LRP) in PyTorch Basic unsupervised implementation of Layer-wise Relevance Propagation (Bach et al., Montavon et al.)

Kai Fabi 28 Dec 26, 2022
Vikrant Deshpande 1 Nov 17, 2022
A scikit-learn compatible neural network library that wraps PyTorch

A scikit-learn compatible neural network library that wraps PyTorch. Resources Documentation Source Code Examples To see more elaborate examples, look

4.9k Dec 31, 2022