Skip to content
Branch: master
Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
dataloader Update Sep 3, 2019
utils Reupload on 21 Aug 2019 Aug 21, 2019 Update Sep 16, 2019 Reupload on 21 Aug 2019 Aug 21, 2019

Meta-Transfer Learning PyTorch

Python PyTorch



In order to run this repository, we advise you to install python 3.5 and PyTorch 0.4.0 with Anaconda.

You may download Anaconda and read the installation instruction on their official website:

Create a new environment and install PyTorch and torchvision on it:

conda create --name mtl-pytorch python=3.5
conda activate mtl-pytorch
conda install pytorch=0.4.0 
conda install torchvision -c pytorch

Install other requirements:

pip install tqdm tensorboardX

Clone this repository:

git clone 
cd meta-transfer-learning/pytorch

Project Architecture

├── data_generator              
|   ├──       # data loader for all datasets
|   └──  # samplers for meta train
├── models                      
|   ├──                  # meta-transfer class
|   ├──           # resnet class
|   └──           # meta-transfer convolution class
├── trainer                     
|   ├──                  # pre-train trainer class
|   └──                 # meta-train trainer class
├── utils                       
|   ├──            # GPU tool functions
|   └──                 # miscellaneous tool functions
├──                     # the python file with main function and parameter settings
├──                  # the script to run pre-train phase
└──                 # the script to run meta-train and meta-test phases

Running Experiments

Run pretrain phase:


Run meta-train and meta-test phase:


Hyperparameters and Options

Hyperparameters and options in

  • model_type The network architecture
  • dataset Meta dataset
  • phase pre-train, meta-train or meta-eval
  • seed Manual seed for PyTorch, "0" means using random seed
  • gpu GPU id
  • dataset_dir Directory for the images
  • max_epoch Epoch number for meta-train phase
  • num_batch The number for different tasks used for meta-train
  • shot Shot number, how many samples for one class in a task
  • way Way number, how many classes in a task
  • train_query The number of training samples for each class in a task
  • val_query The number of test samples for each class in a task
  • meta_lr1 Learning rate for SS weights
  • meta_lr2 Learning rate for FC weights
  • base_lr Learning rate for the inner loop
  • update_step The number of updates for the inner loop
  • step_size The number of epochs to reduce the meta learning rates
  • gamma Gamma for the meta-train learning rate decay
  • init_weights The pretained weights for meta-train phase
  • eval_weights The meta-trained weights for meta-eval phase
  • meta_label Additional label for meta-train
  • pre_max_epoch Epoch number for pre-train pahse
  • pre_batch_size Batch size for pre-train pahse
  • pre_lr Learning rate for pre-train pahse
  • pre_gamma Gamma for the preteain learning rate decay
  • pre_step_size The number of epochs to reduce the pre-train learning rate
  • pre_custom_weight_decay Weight decay for the optimizer during pre-train
You can’t perform that action at this time.