Pytorch implementation of the paper "Optimization as a Model for Few-Shot Learning"

Overview

Optimization as a Model for Few-Shot Learning

This repo provides a Pytorch implementation for the Optimization as a Model for Few-Shot Learning paper.

Installation of pytorch

The experiments needs installing Pytorch

Data

For the miniImageNet you need to download the ImageNet dataset and execute the script utils.create_miniImagenet.py changing the lines:

pathImageNet = '<path_to_downloaded_ImageNet>/ILSVRC2012_img_train'
pathminiImageNet = '<path_to_save_MiniImageNet>/miniImagenet/'

And also change the main file option.py line or pass it by command line arguments:

parser.add_argument('--dataroot', type=str, default='<path_to_save_MiniImageNet>/miniImagenet/',help='path to dataset')

Installation

$ pip install -r requirements.txt
$ python main.py 

Acknowledgements

Special thanks to @sachinravi14 for their Torch implementation. I intend to replicate their code using Pytorch. More details at https://github.com/twitter/meta-learning-lstm

Cite

@inproceedings{Sachin2017,
  title={Optimization as a model for few-shot learning},
  author={Ravi, Sachin and Larochelle, Hugo},
  booktitle={In International Conference on Learning Representations (ICLR)},
  year={2017}
}

Authors

  • Albert Berenguel (@aberenguel) Webpage
Comments
  • Cannot take a larger sample than population when 'replace=False'

    Cannot take a larger sample than population when 'replace=False'

    Hello I have few questions , maybe you could give me some advice. What's the mean of samples_per_class and samples_per_class_eval in miniImagenet.py And I want to used my own data in this program for Binary classification, which parts of the code should I have to alter?

    opened by 378983112 0
  • CUDA out of memory

    CUDA out of memory

    Traceback (most recent call last): File "main.py", line 45, in <module> results = importlib.import_module(opt['metaLearner']).run(opt,data) File "/home/user/myproject/FewShotLearning/model/lstm/train-lstm.py", line 123, in run opt['batchSize'][opt['nTrainShot']]) File "/home/user/anaconda3/envs/FewShotLearning/lib/python2.7/site-packages/torch/nn/modules/module.py", line 489, in __call__ result = self.forward(*input, **kwargs) File "/home/user/myproject/FewShotLearning/model/lstm/metaLearner.py", line 149, in forward output, loss = learner(testInput, testTarget) File "/home/user/anaconda3/envs/FewShotLearning/lib/python2.7/site-packages/torch/nn/modules/module.py", line 489, in __call__ result = self.forward(*input, **kwargs) File "/home/user/myproject/FewShotLearning/model/lstm/learner.py", line 51, in forward output = self.modelF.net(inputs) File "/home/user/anaconda3/envs/FewShotLearning/lib/python2.7/site-packages/torch/nn/modules/module.py", line 489, in __call__ result = self.forward(*input, **kwargs) File "/home/user/myproject/FewShotLearning/model/lstm-classifier.py", line 79, in forward x = self.layer2(x) File "/home/user/anaconda3/envs/FewShotLearning/lib/python2.7/site-packages/torch/nn/modules/module.py", line 489, in __call__ result = self.forward(*input, **kwargs) File "/home/user/anaconda3/envs/FewShotLearning/lib/python2.7/site-packages/torch/nn/modules/container.py", line 92, in forward input = module(input) File "/home/user/anaconda3/envs/FewShotLearning/lib/python2.7/site-packages/torch/nn/modules/module.py", line 489, in __call__ result = self.forward(*input, **kwargs) File "/home/user/anaconda3/envs/FewShotLearning/lib/python2.7/site-packages/torch/nn/modules/batchnorm.py", line 76, in forward exponential_average_factor, self.eps) File "/home/user/anaconda3/envs/FewShotLearning/lib/python2.7/site-packages/torch/nn/functional.py", line 1623, in batch_norm training, momentum, eps, torch.backends.cudnn.enabled RuntimeError: CUDA out of memory. Tried to allocate 16.25 MiB (GPU 0; 11.91 GiB total capacity; 8.65 GiB already allocated; 17.06 MiB free; 950.50 MiB cached) ` nvidia-smi Wed Apr 3 20:53:46 2019
    +-----------------------------------------------------------------------------+ | NVIDIA-SMI 396.26 Driver Version: 396.26 | |-------------------------------+----------------------+----------------------+ | GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC | | Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. | |===============================+======================+======================| | 0 TITAN X (Pascal) Off | 00000000:02:00.0 Off | N/A | | 23% 35C P8 16W / 250W | 1035MiB / 12196MiB | 0% Default | +-------------------------------+----------------------+----------------------+ | 1 TITAN X (Pascal) Off | 00000000:03:00.0 Off | N/A | | 23% 36C P8 18W / 250W | 10MiB / 12196MiB | 0% Default | +-------------------------------+----------------------+----------------------+ | 2 TITAN X (Pascal) Off | 00000000:82:00.0 Off | N/A | | 23% 30C P8 17W / 250W | 10MiB / 12196MiB | 0% Default | +-------------------------------+----------------------+----------------------+ | 3 TITAN X (Pascal) Off | 00000000:83:00.0 Off | N/A | | 23% 33C P8 17W / 250W | 10MiB / 12196MiB | 0% Default | +-------------------------------+----------------------+----------------------+

    +-----------------------------------------------------------------------------+ | Processes: GPU Memory | | GPU PID Type Process name Usage | |=============================================================================| | 0 10217 C ...qun/anaconda2/envs/pt04_py27/bin/python 1021MiB | +-----------------------------------------------------------------------------+ `

    opened by zihaozhang9 3
  • pytorch version?

    pytorch version?

    Traceback (most recent call last): File "main.py", line 39, in results = importlib.import_module(opt['metaLearner']).run(opt,data) File "/home/user/myproject/FewShotLearning/model/lstm/train-lstm.py", line 121, in run opt['batchSize'][opt['nTrainShot']]) File "/home/user/anaconda3/envs/FewShotLearning/lib/python2.7/site-packages/torch/nn/modules/module.py", line 489, in call result = self.forward(*input, **kwargs) File "/home/user/myproject/FewShotLearning/model/lstm/metaLearner.py", line 145, in forward self.lstm2_fS_iS_cS_deltaS) File "/home/user/anaconda3/envs/FewShotLearning/lib/python2.7/site-packages/torch/nn/modules/module.py", line 489, in call result = self.forward(*input, **kwargs) File "/home/user/myproject/FewShotLearning/model/lstm/metalstm.py", line 166, in forward fS_n = torch.stack(fS_n, 0) TypeError: stack(): argument 'tensors' (position 1) must be tuple of Tensors, not Tensor

    opened by zihaozhang9 0
  • Miniimagenet files

    Miniimagenet files

    Hello,

    Thank you for sharing the code. Now I am preparing for the reproduction of your code using miniimagenet. I am wondering if you could provide me the miniimagenet dataset. I would be very grateful for that.

    Thank you very much! [email protected]

    opened by flexibility2 0
  • How to extract miniimagenet from imagenet train dataset downloaded in a folder?

    How to extract miniimagenet from imagenet train dataset downloaded in a folder?

    I have Imagenet 2012 train dataset downloaded and all the tars are extracted together in a single folder. How do get miniimagenet out of it? There are no zero-padded image names in the original dataset.

    opened by SinghGauravKumar 3
Owner
Albert Berenguel Centeno
Phd student and computer vision enthusiast. "There are no secrets to success. It is the result of preparation, hard work, and learning from failure" ColinPowell
Albert Berenguel Centeno
HashNeRF-pytorch - Pure PyTorch Implementation of NVIDIA paper on Instant Training of Neural Graphics primitives

HashNeRF-pytorch Instant-NGP recently introduced a Multi-resolution Hash Encodin

Yash Sanjay Bhalgat 616 Jan 6, 2023
ALBERT-pytorch-implementation - ALBERT pytorch implementation

ALBERT-pytorch-implementation developing... 모델의 개념이해를 돕기 위한 구현물로 현재 변수명을 상세히 적었고

BG Kim 3 Oct 6, 2022
The LaTeX and Python code for generating the paper, experiments' results and visualizations reported in each paper is available (whenever possible) in the paper's directory

This repository contains the software implementation of most algorithms used or developed in my research. The LaTeX and Python code for generating the

João Fonseca 3 Jan 3, 2023
Official PyTorch implementation for paper Context Matters: Graph-based Self-supervised Representation Learning for Medical Images

Context Matters: Graph-based Self-supervised Representation Learning for Medical Images Official PyTorch implementation for paper Context Matters: Gra

null 49 Nov 23, 2022
A PyTorch re-implementation of the paper 'Exploring Simple Siamese Representation Learning'. Reproduced the 67.8% Top1 Acc on ImageNet.

Exploring simple siamese representation learning This is a PyTorch re-implementation of the SimSiam paper on ImageNet dataset. The results match that

Taojiannan Yang 72 Nov 9, 2022
This is a Pytorch implementation of the paper: Self-Supervised Graph Transformer on Large-Scale Molecular Data.

This is a Pytorch implementation of the paper: Self-Supervised Graph Transformer on Large-Scale Molecular Data.

null 212 Dec 25, 2022
Official pytorch implementation of paper "Image-to-image Translation via Hierarchical Style Disentanglement".

HiSD: Image-to-image Translation via Hierarchical Style Disentanglement Official pytorch implementation of paper "Image-to-image Translation

null 364 Dec 14, 2022
PyTorch implementation of paper "Neural Scene Flow Fields for Space-Time View Synthesis of Dynamic Scenes", CVPR 2021

Neural Scene Flow Fields PyTorch implementation of paper "Neural Scene Flow Fields for Space-Time View Synthesis of Dynamic Scenes", CVPR 20

Zhengqi Li 585 Jan 4, 2023
Official pytorch implementation of paper "Inception Convolution with Efficient Dilation Search" (CVPR 2021 Oral).

IC-Conv This repository is an official implementation of the paper Inception Convolution with Efficient Dilation Search. Getting Started Download Imag

Jie Liu 111 Dec 31, 2022
Official implementation of our paper "LLA: Loss-aware Label Assignment for Dense Pedestrian Detection" in Pytorch.

LLA: Loss-aware Label Assignment for Dense Pedestrian Detection This project provides an implementation for "LLA: Loss-aware Label Assignment for Dens

null 35 Dec 6, 2022
An implementation of Geoffrey Hinton's paper "How to represent part-whole hierarchies in a neural network" in Pytorch.

GLOM An implementation of Geoffrey Hinton's paper "How to represent part-whole hierarchies in a neural network" for MNIST Dataset. To understand this

null 50 Oct 19, 2022
Official implementation of our CVPR2021 paper "OTA: Optimal Transport Assignment for Object Detection" in Pytorch.

OTA: Optimal Transport Assignment for Object Detection This project provides an implementation for our CVPR2021 paper "OTA: Optimal Transport Assignme

null 217 Jan 3, 2023
This is the official PyTorch implementation of the paper "TransFG: A Transformer Architecture for Fine-grained Recognition" (Ju He, Jie-Neng Chen, Shuai Liu, Adam Kortylewski, Cheng Yang, Yutong Bai, Changhu Wang, Alan Yuille).

TransFG: A Transformer Architecture for Fine-grained Recognition Official PyTorch code for the paper: TransFG: A Transformer Architecture for Fine-gra

Ju He 307 Jan 3, 2023
[PyTorch] Official implementation of CVPR2021 paper "PointDSC: Robust Point Cloud Registration using Deep Spatial Consistency". https://arxiv.org/abs/2103.05465

PointDSC repository PyTorch implementation of PointDSC for CVPR'2021 paper "PointDSC: Robust Point Cloud Registration using Deep Spatial Consistency",

null 153 Dec 14, 2022
PyTorch implementation of the Deep SLDA method from our CVPRW-2020 paper "Lifelong Machine Learning with Deep Streaming Linear Discriminant Analysis"

Lifelong Machine Learning with Deep Streaming Linear Discriminant Analysis This is a PyTorch implementation of the Deep Streaming Linear Discriminant

Tyler Hayes 41 Dec 25, 2022
The official pytorch implementation of our paper "Is Space-Time Attention All You Need for Video Understanding?"

TimeSformer This is an official pytorch implementation of Is Space-Time Attention All You Need for Video Understanding?. In this repository, we provid

Facebook Research 1k Dec 31, 2022
PyTorch 1.5 implementation for paper DECOR-GAN: 3D Shape Detailization by Conditional Refinement.

DECOR-GAN PyTorch 1.5 implementation for paper DECOR-GAN: 3D Shape Detailization by Conditional Refinement, Zhiqin Chen, Vladimir G. Kim, Matthew Fish

Zhiqin Chen 72 Dec 31, 2022
Pytorch implementation of our paper under review — Lottery Jackpots Exist in Pre-trained Models

Lottery Jackpots Exist in Pre-trained Models (Paper Link) Requirements Python >= 3.7.4 Pytorch >= 1.6.1 Torchvision >= 0.4.1 Reproduce the Experiment

Yuxin Zhang 27 Jun 28, 2022
Official Pytorch Implementation of: "ImageNet-21K Pretraining for the Masses"(2021) paper

ImageNet-21K Pretraining for the Masses Paper | Pretrained models Official PyTorch Implementation Tal Ridnik, Emanuel Ben-Baruch, Asaf Noy, Lihi Zelni

null 574 Jan 2, 2023