Train/test existing methods in LibFewShot

Code for this section:


In this section, we take the DN4 method as an example to describe how to train and test an implemented method.

Configuration files

In, we have showed how to write a configuration file. We also assemble some of the common configuration into the public file, so that you can easily finish your DN4 configuration file.

	- headers/data.yaml
	- headers/device.yaml
	- headers/misc.yaml
	- headers/optimizer.yaml
	- backbones/resnet12.yaml
	- classifiers/DN4.yaml

For specific customer requirements, you can modify the related included files or use other files and add your own configuration.


Name the configuration file we have finished in previous section as dn4.yaml, place it into the config/ directory.

Modify the file in project root as follow:

config = Config("./config/dn4.yaml").get_config_dict()

Next, run this instruction in your shell


and the training will start.


Modify the file in project root as follow:

import os
from core.config import Config
from core.test import Test

PATH = "./results/DN4-miniImageNet-resnet12-5-5"
    "test_epoch": 5,
    "device_ids": "4",
    "n_gpu": 1,
    "test_episode": 600,
    "episode_size": 1,

def main(rank, config):
    test = Test(rank, config, PATH)

if __name__ == "__main__":
    config = Config(os.path.join(PATH, "config.yaml"), VAR_DICT).get_config_dict()

    if config["n_gpu"] > 1:
        os.environ["CUDA_VISIBLE_DEVICES"] = config["device_ids"]
        torch.multiprocessing.spawn(main, nprocs=config["n_gpu"], args=(config,))
        main(0, config)

Input in your shell:


and the testing will start.

Of course, all of the VAR_DICT variables can be removed, by running instruction as follows

python --test_epoch 5 --device_ids 4 --n_gpu 1 --test_episode 600 --episode_size 1

to achieve the same effect.