In order to run this repository, we advise you to install python 2.7 or 3.5 and TensorFlow 1.3.0 with Anaconda.
You may download Anaconda and read the installation instruction on their official website: https://www.anaconda.com/download/
Create a new environment and install tensorflow on it:
conda create --name mtl-tf python=2.7
conda activate mtl-tf
conda install tensorflow-gpu=1.3.0Install other requirements:
pip install scipy tqdm opencv-python pillow matplotlib miniimagenettoolsClone this repository:
git clone https://github.com/yaoyao-liu/meta-transfer-learning.git
cd meta-transfer-learning/tensorflow.
├── data_generator # dataset generator
| ├── pre_data_generator.py # data genertor for pre-train phase
| └── meta_data_generator.py # data genertor for meta-train phase
├── models # tensorflow model files
| ├── resnet12.py # resnet12 class
| ├── resnet18.py # resnet18 class
| ├── pre_model.py # pre-train model class
| └── meta_model.py # meta-train model class
├── trainer # tensorflow trianer files
| ├── pre.py # pre-train trainer class
| └── meta.py # meta-train trainer class
├── utils # a series of tools used in this repo
| └── misc.py # miscellaneous tool functions
├── main.py # the python file with main function and parameter settings
└── run_experiment.py # the script to run the whole experiment
Run pre-train phase:
python run_experiment.py PRERun meta-train and meta-test phase:
python run_experiment.py METAYou may edit the run_experiment.py file to change the hyperparameters and options.
LOG_DIRName of the folder to save the log filesGPU_IDGPU device idNET_ARCHNetwork backbone (resnet12 or resnet18)PRE_TRA_LABELAdditional label for pre-train modelPRE_TRA_ITER_MAXIteration number for the pre-train phasePRE_TRA_DROPDropout keep rate for the pre-train phasePRE_DROP_STEPIteration number for the pre-train learning rate reducingPRE_LRPre-train learning rateSHOT_NUMSample number for each classWAY_NUMClass number for the few-shot tasksMAX_MAX_ITERIteration number for meta-train phaseMETA_BATCH_SIZEMeta batch sizePRE_ITERIteration number for the pre-train model used in the meta-train phaseUPDATE_NUMEpoch number for the base learningSAVE_STEPIteration number to save the meta modelMETA_LRMeta learning rateMETA_LR_MINMeta learning rate min valueLR_DROP_STEPIteration number for the meta learning rate reducingBASE_LRBase learning ratePRE_TRA_DIRDirectory for the pre-train phase imagesMETA_TRA_DIRDirectory for the meta-train imagesMETA_VAL_DIRDirectory for the meta-validation imagesMETA_TES_DIRDirectory for the meta-test images
The file run_experiment.py is just a script to generate commands for main.py. If you want to change other settings, please see the comments and descriptions in main.py.
In the default setting, if you run python run_experiment.py, the pretrain process will be conducted before the meta-train phase starts. If you want to use the model pretrained by us, you may download the model by the following link. To run experiments with the downloaded model, please make sure you are using python 2.7.
Comparison of the original paper and the open-source code in terms of test set accuracy:
Download models: [Google Drive]
Move the downloaded npy files to ./logs/download_weights (e.g. 𝑚𝑖𝑛𝑖ImageNet, 1-shot):
mkdir -p ./logs/download_weights
mv ~/downloads/mini-1shot/*.npy ./logs/download_weightsRun meta-train with downloaded model:
python run_experiment.py META_LOADRun meta-test with downloaded model:
python run_experiment.py TEST_LOAD