LibFewShot: A Comprehensive Library for Few-shot Learning.

Overview

LibFewShot

Make few-shot learning easy.

Supported Methods

Meta

Metric

Finetuning

Quick Installnation

Please refer to install.md(安装) for installation.

Full tutorials can be found at document(中文文档).

Contributing

Feel free to contribute any kind of function or enhancement, here the coding style follows PEP8. Please refer to contributing.md(贡献代码) for the contributing guideline.

License

This project is licensed under the MIT License. See LICENSE for more details

Acknowledgement

LibFewShot is an open source project designed to help few shot learning researchers quickly understand the classic methods and code structures. We welcome other contributors to use the LibFewShot framework to implement some methods and add them to this library. This library can be used for academic research. We welcome researchers in the field of fes shot learning to use LibFewShot to implement their own methods, and welcome feedback when using LibFewShot. We will try our best to improve the library.

Citation

If you use this code for your research, please cite our paper.

@article{li2021LibFewShot,
  title={LibFewShot: A Comprehensive Library for Few-shot Learning},
  author={Wenbin Li, Chuanqi Dong, Pinzhuo Tian, Tiexin Qin, Xuesong Yang, Ziyi Wang, Jing Huo, Yinghuan Shi, Lei Wang, Yang Gao, Jiebo Luo},
  journal={arXiv preprint arXiv:2109.04898},
  year={2021}
}
Comments
  • 在miniImageNet数据集上运行RENet等报错

    在miniImageNet数据集上运行RENet等报错

    (torchLFS) [inspur@localhost LibFewShot-main]$ python run_trainer.py [11/14/22 10:04:36] INFO {'data_root': '/home/inspur/MAX_SPACE/Jiyu/LibFewShot-main/dataset_floder/miniImgFSL', 'image_size': 84, 'use_memory': False, 'augment': trainer.py:372 False, 'augment_times': 1, 'augment_times_query': 1, 'workers': 2, 'dataloader_num': 1, 'device_ids': 0, 'n_gpu': 1, 'seed': 2147483647,
    'deterministic': True, 'port': 53758, 'log_name': None, 'log_level': 'info', 'log_interval': 100, 'log_paramerter': False, 'result_root':
    './results', 'save_interval': 10, 'save_part': ['emb_func'], 'tag': None, 'epoch': 5, 'test_epoch': 5, 'parallel_part': ['emb_func'],
    'pretrain_path': None, 'resume': False, 'way_num': 5, 'shot_num': 1, 'query_num': 15, 'test_way': 5, 'test_shot': 1, 'test_query': 15,
    'episode_size': 1, 'train_episode': 100, 'test_episode': 100, 'batch_size': 128, 'val_per_epoch': 1, 'optimizer': {'name': 'Adam',
    'kwargs': {'lr': 0.01}, 'other': None}, 'lr_scheduler': {'name': 'StepLR', 'kwargs': {'gamma': 1.0, 'step_size': 20}}, 'warmup': 0,
    'includes': ['headers/data.yaml', 'headers/device.yaml', 'headers/misc.yaml', 'headers/model.yaml', 'headers/optimizer.yaml',
    'classifiers/RENet.yaml', 'backbones/resnet18.yaml'], 'classifier': {'name': 'RENet', 'kwargs': {'feat_dim': 512, 'lambda_epi': 0.25,
    'temperature': 0.2, 'temperature_attn': 5.0, 'num_classes': 2}}, 'backbone': {'name': 'resnet18', 'kwargs': {'is_feature': False,
    'avg_pool': True, 'is_flatten': True}}, 'tb_scale': 1.0, 'rank': 0}
    [11/14/22 10:04:37] INFO RENet( trainer.py:372 (emb_func): ResNet(
    (conv1): Conv2d(3, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
    (bn1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
    (relu): ReLU(inplace=True)
    (layer1): Sequential(
    (0): BasicBlock(
    (conv1): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
    (bn1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
    (relu): ReLU(inplace=True)
    (conv2): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
    (bn2): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
    )
    (1): BasicBlock(
    (conv1): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
    (bn1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
    (relu): ReLU(inplace=True)
    (conv2): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
    (bn2): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
    )
    )
    (layer2): Sequential(
    (0): BasicBlock(
    (conv1): Conv2d(64, 128, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), bias=False)
    (bn1): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
    (relu): ReLU(inplace=True)
    (conv2): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
    (bn2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
    (downsample): Sequential(
    (0): Conv2d(64, 128, kernel_size=(1, 1), stride=(2, 2), bias=False)
    (1): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
    )
    )
    (1): BasicBlock(
    (conv1): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
    (bn1): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
    (relu): ReLU(inplace=True)
    (conv2): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
    (bn2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
    )
    )
    (layer3): Sequential(
    (0): BasicBlock(
    (conv1): Conv2d(128, 256, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), bias=False)
    (bn1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
    (relu): ReLU(inplace=True)
    (conv2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
    (bn2): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
    (downsample): Sequential(
    (0): Conv2d(128, 256, kernel_size=(1, 1), stride=(2, 2), bias=False)
    (1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
    )
    )
    (1): BasicBlock(
    (conv1): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
    (bn1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
    (relu): ReLU(inplace=True)
    (conv2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
    (bn2): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
    )
    )
    (layer4): Sequential(
    (0): BasicBlock(
    (conv1): Conv2d(256, 512, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), bias=False)
    (bn1): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
    (relu): ReLU(inplace=True)
    (conv2): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
    (bn2): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
    (downsample): Sequential(
    (0): Conv2d(256, 512, kernel_size=(1, 1), stride=(2, 2), bias=False)
    (1): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
    )
    )
    (1): BasicBlock(
    (conv1): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
    (bn1): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
    (relu): ReLU(inplace=True)
    (conv2): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
    (bn2): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
    )
    )
    (avgpool): AdaptiveAvgPool2d(output_size=(1, 1))
    )
    (fc): Linear(in_features=512, out_features=2, bias=True)
    (scr_layer): SCRLayer(
    (model): Sequential(
    (0): SelfCorrelationComputation(
    (unfold): Unfold(kernel_size=(5, 5), dilation=1, padding=2, stride=1)
    (relu): ReLU()
    )
    (1): SCR(
    (conv1x1_in): Sequential(
    (0): Conv2d(512, 64, kernel_size=(1, 1), stride=(1, 1), bias=False)
    (1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
    (2): ReLU(inplace=True)
    )
    (conv1): Sequential(
    (0): Conv3d(64, 64, kernel_size=(1, 3, 3), stride=(1, 1, 1), bias=False)
    (1): BatchNorm3d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
    (2): ReLU(inplace=True)
    )
    (conv2): Sequential(
    (0): Conv3d(64, 64, kernel_size=(1, 3, 3), stride=(1, 1, 1), bias=False)
    (1): BatchNorm3d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
    (2): ReLU(inplace=True)
    )
    (conv1x1_out): Sequential(
    (0): Conv2d(64, 512, kernel_size=(1, 1), stride=(1, 1), bias=False)
    (1): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
    )
    )
    )
    )
    (cca_layer): CCALayer(
    (cca_module): CCA(
    (conv): Sequential(
    (0): SepConv4d(
    (proj): Sequential(
    (0): Conv2d(1, 16, kernel_size=(1, 1), stride=(1, 1), bias=False)
    (1): BatchNorm2d(16, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
    )
    (conv1): Sequential(
    (0): Conv3d(1, 1, kernel_size=(1, 3, 3), stride=(1, 1, 1), padding=(0, 1, 1), bias=False)
    (1): BatchNorm3d(1, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
    )
    (conv2): Sequential(
    (0): Conv3d(1, 1, kernel_size=(3, 3, 1), stride=(1, 1, 1), padding=(1, 1, 0), bias=False)
    (1): BatchNorm3d(1, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
    )
    (relu): ReLU(inplace=True)
    )
    (1): ReLU(inplace=True)
    (2): SepConv4d(
    (proj): Sequential(
    (0): Conv2d(16, 1, kernel_size=(1, 1), stride=(1, 1), bias=False)
    (1): BatchNorm2d(1, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
    )
    (conv1): Sequential(
    (0): Conv3d(16, 16, kernel_size=(1, 3, 3), stride=(1, 1, 1), padding=(0, 1, 1), bias=False)
    (1): BatchNorm3d(16, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
    )
    (conv2): Sequential(
    (0): Conv3d(16, 16, kernel_size=(3, 3, 1), stride=(1, 1, 1), padding=(1, 1, 0), bias=False)
    (1): BatchNorm3d(16, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
    )
    (relu): ReLU(inplace=True)
    )
    )
    )
    (cca_1x1): Sequential(
    (0): Conv2d(512, 64, kernel_size=(1, 1), stride=(1, 1), bias=False)
    (1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
    (2): ReLU()
    )
    )
    (loss_func): CrossEntropyLoss()
    )
    INFO Trainable params in the model: 11348186 trainer.py:372 [11/14/22 10:04:40] INFO load 38400 train image with 64 label. trainer.py:372 INFO load 9600 val image with 16 label. trainer.py:372 INFO load 12000 test image with 20 label. trainer.py:372 INFO Adam ( trainer.py:372 Parameter Group 0
    amsgrad: False
    betas: (0.9, 0.999)
    eps: 1e-08
    initial_lr: 0.01
    lr: 0.01
    weight_decay: 0
    )
    INFO ============ Train on the train set ============ trainer.py:372 INFO learning rate: [0.01] trainer.py:372 Traceback (most recent call last): File "run_trainer.py", line 24, in main(0, config) File "run_trainer.py", line 14, in main trainer.train_loop(rank) File "/home/inspur/MAX_SPACE/Jiyu/LibFewShot-main/core/trainer.py", line 83, in train_loop train_acc = self._train(epoch_idx) File "/home/inspur/MAX_SPACE/Jiyu/LibFewShot-main/core/trainer.py", line 170, in _train [elem for each_batch in batch for elem in each_batch] File "/home/inspur/anaconda3/envs/torchLFS/lib/python3.7/site-packages/torch/nn/modules/module.py", line 727, in _call_impl result = self.forward(*input, **kwargs) File "/home/inspur/MAX_SPACE/Jiyu/LibFewShot-main/core/model/abstract_model.py", line 30, in forward return self.set_forward_loss(x) File "/home/inspur/MAX_SPACE/Jiyu/LibFewShot-main/core/model/finetuning/renet.py", line 415, in set_forward_loss ) = batch # RENet uses both episode and general dataloaders ValueError: not enough values to unpack (expected 4, got 2)

    opened by Aquariuaa 9
  • Issue about training the supported methods

    Issue about training the supported methods

    Hi. I have installed LibFewShot successfully, and got correct output by running test_install.yaml. However, the script gave the following error message when I tried to run other supported methods listed in ./config. 截屏2021-10-25 下午4 44 45 Could you give some suggestions about how to solve such problem?

    opened by viviGeng 6
  • Questions about using the given dataset for training(such as miniImagenet) and using my own dataset for testing!

    Questions about using the given dataset for training(such as miniImagenet) and using my own dataset for testing!

    Hello, as described in the title, how do I handle my own dataset after training with the miniImagenet dataset you have given ? For example,my dataset has 4 classes and each class has about 100 images, Do I need to process my dataset into the following format?

    MyDataset_folder/ ├── images/ │ ├── images_1.jpg │ ├── ... │ └── images_n.jpg ├── train.csv * ├── test.csv * └── val.csv *

    Or do I need to put all my datasets into the miniImagenet dataset and create a new test.csv to replace the original test.csv in the miniImagenet dataset?

    Or other methods?

    Look forward to your reply, thank you!

    opened by MasterWinston 5
  • shape '[1, 5, 20]' is invalid for input of size 25 when running run_trainer.py

    shape '[1, 5, 20]' is invalid for input of size 25 when running run_trainer.py

    Hi,

    I'm trying to use your library with a custom dataset that I created with images retreived from google image. The train/val.csv file is composed of seven classes each with 5 examples and the test.csv is composed of one image of each classes (see below pictures).

    I have also the following .yaml config file that I -more or less - copy-pasted from your documentation,

    includes:
      - headers/dataZSL.yaml
      - headers/device.yaml
      - headers/misc.yaml
      - headers/model.yaml
      - headers/optimizer.yaml
      - classifiers/Proto.yaml
      - backbones/Conv64F.yaml
    
    
    epoch: 50
    test_epoch: 5
    
    pretrain_path: ~
    resume: False
    
    way_num: 5
    shot_num: 5
    query_num: 15
    test_way: ~
    test_shot: ~
    test_query: ~
    episode_size: 1
    # batch_size only works in pre-train
    batch_size: 128
    train_episode: 10000
    test_episode: 1000
    
    backbone:
      name: Conv64F
      kwargs:
        is_flatten: True
        is_feature: False
        leaky_relu: False
        negative_slope: 0.2
        last_pool: True
    

    the dataZSL.yaml file referenced in the header is the following file,

    data_root: ./core/data/fewshot/zslDataset
    image_size: 84
    use_memory: False
    augment: True
    augment_times: 1
    augment_times_query: 1
    

    If that is useful, I will precise that I'm using google colab to run the code. With all that said, when I try to lunch the run_trainer.py program the following error occurs,

    Traceback (most recent call last): File "run_trainer.py", line 12, in trainer.train_loop() File "/content/drive/MyDrive/Colab Notebooks/LibFewShot/core/trainer.py", line 72, in train_loop train_acc = self._train(epoch_idx) File "/content/drive/MyDrive/Colab Notebooks/LibFewShot/core/trainer.py", line 119, in _train prefetcher = data_prefetcher(self.train_loader) File "/content/drive/MyDrive/Colab Notebooks/LibFewShot/core/utils/utils.py", line 288, in init self.preload() File "/content/drive/MyDrive/Colab Notebooks/LibFewShot/core/utils/utils.py", line 292, in preload self.next_data = next(self.loader) File "/usr/local/lib/python3.7/dist-packages/torch/utils/data/dataloader.py", line 530, in next data = self._next_data() File "/usr/local/lib/python3.7/dist-packages/torch/utils/data/dataloader.py", line 1224, in _next_data return self._process_data(data) File "/usr/local/lib/python3.7/dist-packages/torch/utils/data/dataloader.py", line 1250, in _process_data data.reraise() File "/usr/local/lib/python3.7/dist-packages/torch/_utils.py", line 457, in reraise raise exception RuntimeError: Caught RuntimeError in DataLoader worker process 0. Original Traceback (most recent call last): File "/usr/local/lib/python3.7/dist-packages/torch/utils/data/_utils/worker.py", line 287, in _worker_loop data = fetcher.fetch(index) File "/usr/local/lib/python3.7/dist-packages/torch/utils/data/_utils/fetch.py", line 52, in fetch return self.collate_fn(data) File "/content/drive/MyDrive/Colab Notebooks/LibFewShot/core/data/collates/collate_functions.py", line 169, in call return self.method(batch) File "/content/drive/MyDrive/Colab Notebooks/LibFewShot/core/data/collates/collate_functions.py", line 149, in method self.episode_size, self.way_num, self.shot_num + self.query_num RuntimeError: shape '[1, 5, 20]' is invalid for input of size 25

    I must say that I am quite lost in how to resolve this problem. If I can provide more information, don't hesitate to ask, Thank you.

    train the two first classes in train.csv

    test the test.csv file

    PS : I removed the first column in the lib code in dataset.py in order to only get the two columns of interest

    opened by Akutchi 5
  • Accuracy of CAN Method

    Accuracy of CAN Method

    Hi, I tried to reproduce the accuracy of CAN method. However, the accuracy turns out to be weird. So that I print the intermediate steps and the returned value once line 327 in can.py is called.

    acc = accuracy(cls_scores, query_targets, topk=1)
    

    One example of output:

    batch_size:  1
    correct:  tensor([[1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 1, 0, 0, 1,
             1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 0,
             0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0,
             0, 0, 0]], device='cuda:0', dtype=torch.uint8)
    correct_k:  tensor([30.], device='cuda:0')
     acc:  3000.0
    

    The accuracy is too large. Also, the batch_size is set as 128 in the config file, rather than the output value 1.

    opened by viviGeng 4
  • 关于LEO的复现

    关于LEO的复现

    你好,首先感谢你们对多种小样本方法的复现及开源。

    在运行leo.yaml配置时我注意到它需要pretrain的模型:pretrain_path: ./results/checkpoint.pth。请问这个模型是用什么方法预训练的呢?

    另外在运行其它方法时,根据给出的配置我跑出了和论文差距不小的结果,我注意到您在 #9 中提到过将放出具体配置,请问目前有哪些方法已经整理好了配置,能否更新一下,十分感谢!

    opened by Skyraker2016 4
  • maml 方法似乎不支持多gpu训练

    maml 方法似乎不支持多gpu训练

    maml方法能在单个gpu上训练,但在多个gpu上平行训练会报错。具体错误如下:

      File "/home/cougarnet.uh.edu/pyuan2/anaconda3/envs/py37/lib/python3.7/site-packages/torch/nn/parallel/parallel_apply.py", line 61, in _worker
        output = module(*input, **kwargs)
      File "/home/cougarnet.uh.edu/pyuan2/anaconda3/envs/py37/lib/python3.7/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
        result = self.forward(*input, **kwargs)
      File "/home/cougarnet.uh.edu/pyuan2/Projects/LibFewShot/core/model/backbone/conv_four.py", line 69, in forward
        out1 = self.layer1(x)
      File "/home/cougarnet.uh.edu/pyuan2/anaconda3/envs/py37/lib/python3.7/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
        result = self.forward(*input, **kwargs)
      File "/home/cougarnet.uh.edu/pyuan2/anaconda3/envs/py37/lib/python3.7/site-packages/torch/nn/modules/container.py", line 117, in forward
        input = module(input)
      File "/home/cougarnet.uh.edu/pyuan2/anaconda3/envs/py37/lib/python3.7/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
        result = self.forward(*input, **kwargs)
      File "/home/cougarnet.uh.edu/pyuan2/Projects/LibFewShot/core/model/backbone/utils/maml_module.py", line 63, in forward
        if self.weight.fast is not None and self.bias.fast is not None:
    AttributeError: 'Tensor' object has no attribute 'fast'
    
    opened by ypy516478793 4
  • FileNotFoundError: [Errno 2] No such file or directory: './config/backbones/Conv64FLeakyReLU.yaml'

    FileNotFoundError: [Errno 2] No such file or directory: './config/backbones/Conv64FLeakyReLU.yaml'

    Thank you very much! The following documents are missing : FileNotFoundError: [Errno 2] No such file or directory: './config/backbones/Conv64FLeakyReLU.yaml'

    opened by Aquariuaa 3
  • TypeError: __init__() missing 1 required positional argument: 'config'

    TypeError: __init__() missing 1 required positional argument: 'config'

    Traceback (most recent call last): File "E:/code/mildew/LibFewShot/run_trainer.py", line 31, in trainer = Trainer(config) TypeError: init() missing 1 required positional argument: 'config'

    opened by yy-wy 3
  • Protonet

    Protonet

    你好,我在Protonet网络中计算距离矩阵时乘以了0.01,发现训练准确率提升了,请问这个是正常的吗?还是说最终的准确率与距离的数量级也有关系。 "euclidean": lambda x, y: -0.01*torch.sum( torch.pow(x.unsqueeze(2) - y.unsqueeze(1), 2), dim=3,

    opened by ch-control 3
  • Training CAN with a Resnet12 backbone on miniImageNet

    Training CAN with a Resnet12 backbone on miniImageNet

    I was trying to reproduce some results from the paper, and had no problem training CAN with a Conv64 backbone using the can.yaml file. However, when using Resnet12 as the backbone I had to lower episode_size to 2 (otherwise I'd get a CUDA out of memory error), and after that I couldn't figure out a working configuration to get the training started. Can someone help me out?

    config file:

    includes:
      - headers/data.yaml
      - headers/device.yaml
      - headers/misc.yaml
      - headers/model.yaml
      - headers/optimizer.yaml
      - classifiers/CAN.yaml
      - backbones/Conv64F.yaml
    
    episode_size: 2
    
    classifier:
      name: CAN
      kwargs:
        scale_cls: 7 # default
        num_class: 64
        nFeat: 64
        HW: 10
    
    # backbone:
    #   name: Conv64F
    #   kwargs:
    #     is_flatten: False
    #     is_feature: False
    #     leaky_relu: True
    #     negative_slope: 0.2
    #     last_pool: False
    
    backbone:
      name: resnet12
      kwargs:
        maxpool_last2: False
        is_flatten: False
    
    # need to modify: core/model/backbone/resnet_18.py:114 stride=1
    # backbone:
    #   name: resnet18
    #   kwargs:
    #     is_flatten: False
    #     avg_pool: False
    
    #backbone:
    #  name: WRN
    #  kwargs:
    #    depth: 28
    #    widen_factor: 10
    #    avg_pool: False
    #    is_flatten: False
    

    log:

    [11/18/21 12:49:40] INFO     {'data_root':                         trainer.py:50
                                 '/storage/miniImageNet--ravi',
                                 'image_size': 84, 'use_memory':
                                 False, 'augment': True,
                                 'augment_times': 1,
                                 'augment_times_query': 1,
                                 'device_ids': 0, 'n_gpu': 1, 'seed':
                                 0, 'deterministic': True, 'log_name':
                                 None, 'log_level': 'info',
                                 'log_interval': 100,
                                 'log_paramerter': False,
                                 'result_root': './results',
                                 'save_interval': 10, 'save_part':
                                 ['emb_func'], 'tag': None, 'epoch':
                                 50, 'test_epoch': 5, 'parallel_part':
                                 ['emb_func'], 'pretrain_path': None,
                                 'resume': False, 'way_num': 5,
                                 'shot_num': 1, 'query_num': 15,
                                 'test_way': 5, 'test_shot': 1,
                                 'test_query': 15, 'episode_size': 2,
                                 'train_episode': 100, 'test_episode':
                                 100, 'batch_size': 128, 'optimizer':
                                 {'name': 'Adam', 'kwargs': {'lr':
                                 0.001}, 'other': {'emb_func':
                                 0.001}}, 'lr_scheduler': {'name':
                                 'StepLR', 'kwargs': {'gamma': 0.5,
                                 'step_size': 10}}, 'includes':
                                 ['headers/data.yaml',
                                 'headers/device.yaml',
                                 'headers/misc.yaml',
                                 'headers/model.yaml',
                                 'headers/optimizer.yaml',
                                 'classifiers/CAN.yaml',
                                 'backbones/Conv64F.yaml'],
                                 'classifier': {'name': 'CAN',
                                 'kwargs': {'scale_cls': 7,
                                 'num_class': 64, 'nFeat': 64, 'HW':
                                 10}}, 'backbone': {'name':
                                 'resnet12', 'kwargs':
                                 {'maxpool_last2': False,
                                 'is_flatten': False}}, 'tb_scale':
                                 1.0}
                        INFO     CAN(                                 trainer.py:355
                                   (emb_func): ResNet(
                                     (layer1): Sequential(
                                       (0): BasicBlock(
                                         (conv1): Conv2d(3, 64,
                                 kernel_size=(3, 3), stride=(1, 1),
                                 padding=(1, 1), bias=False)
                                         (bn1): BatchNorm2d(64,
                                 eps=1e-05, momentum=0.1,
                                 affine=True,
                                 track_running_stats=True)
                                         (relu):
                                 LeakyReLU(negative_slope=0.1)
                                         (conv2): Conv2d(64, 64,
                                 kernel_size=(3, 3), stride=(1, 1),
                                 padding=(1, 1), bias=False)
                                         (bn2): BatchNorm2d(64,
                                 eps=1e-05, momentum=0.1,
                                 affine=True,
                                 track_running_stats=True)
                                         (conv3): Conv2d(64, 64,
                                 kernel_size=(3, 3), stride=(1, 1),
                                 padding=(1, 1), bias=False)
                                         (bn3): BatchNorm2d(64,
                                 eps=1e-05, momentum=0.1,
                                 affine=True,
                                 track_running_stats=True)
                                         (maxpool):
                                 MaxPool2d(kernel_size=2, stride=2,
                                 padding=0, dilation=1,
                                 ceil_mode=False)
                                         (downsample): Sequential(
                                           (0): Conv2d(3, 64,
                                 kernel_size=(1, 1), stride=(1, 1),
                                 bias=False)
                                           (1): BatchNorm2d(64,
                                 eps=1e-05, momentum=0.1,
                                 affine=True,
                                 track_running_stats=True)
                                         )
                                         (DropBlock): DropBlock()
                                       )
                                     )
                                     (layer2): Sequential(
                                       (0): BasicBlock(
                                         (conv1): Conv2d(64, 160,
                                 kernel_size=(3, 3), stride=(1, 1),
                                 padding=(1, 1), bias=False)
                                         (bn1): BatchNorm2d(160,
                                 eps=1e-05, momentum=0.1,
                                 affine=True,
                                 track_running_stats=True)
                                         (relu):
                                 LeakyReLU(negative_slope=0.1)
                                         (conv2): Conv2d(160, 160,
                                 kernel_size=(3, 3), stride=(1, 1),
                                 padding=(1, 1), bias=False)
                                         (bn2): BatchNorm2d(160,
                                 eps=1e-05, momentum=0.1,
                                 affine=True,
                                 track_running_stats=True)
                                         (conv3): Conv2d(160, 160,
                                 kernel_size=(3, 3), stride=(1, 1),
                                 padding=(1, 1), bias=False)
                                         (bn3): BatchNorm2d(160,
                                 eps=1e-05, momentum=0.1,
                                 affine=True,
                                 track_running_stats=True)
                                         (maxpool):
                                 MaxPool2d(kernel_size=2, stride=2,
                                 padding=0, dilation=1,
                                 ceil_mode=False)
                                         (downsample): Sequential(
                                           (0): Conv2d(64, 160,
                                 kernel_size=(1, 1), stride=(1, 1),
                                 bias=False)
                                           (1): BatchNorm2d(160,
                                 eps=1e-05, momentum=0.1,
                                 affine=True,
                                 track_running_stats=True)
                                         )
                                         (DropBlock): DropBlock()
                                       )
                                     )
                                     (layer3): Sequential(
                                       (0): BasicBlock(
                                         (conv1): Conv2d(160, 320,
                                 kernel_size=(3, 3), stride=(1, 1),
                                 padding=(1, 1), bias=False)
                                         (bn1): BatchNorm2d(320,
                                 eps=1e-05, momentum=0.1,
                                 affine=True,
                                 track_running_stats=True)
                                         (relu):
                                 LeakyReLU(negative_slope=0.1)
                                         (conv2): Conv2d(320, 320,
                                 kernel_size=(3, 3), stride=(1, 1),
                                 padding=(1, 1), bias=False)
                                         (bn2): BatchNorm2d(320,
                                 eps=1e-05, momentum=0.1,
                                 affine=True,
                                 track_running_stats=True)
                                         (conv3): Conv2d(320, 320,
                                 kernel_size=(3, 3), stride=(1, 1),
                                 padding=(1, 1), bias=False)
                                         (bn3): BatchNorm2d(320,
                                 eps=1e-05, momentum=0.1,
                                 affine=True,
                                 track_running_stats=True)
                                         (maxpool):
                                 MaxPool2d(kernel_size=2, stride=2,
                                 padding=0, dilation=1,
                                 ceil_mode=False)
                                         (downsample): Sequential(
                                           (0): Conv2d(160, 320,
                                 kernel_size=(1, 1), stride=(1, 1),
                                 bias=False)
                                           (1): BatchNorm2d(320,
                                 eps=1e-05, momentum=0.1,
                                 affine=True,
                                 track_running_stats=True)
                                         )
                                         (DropBlock): DropBlock()
                                       )
                                     )
                                     (layer4): Sequential(
                                       (0): BasicBlock(
                                         (conv1): Conv2d(320, 640,
                                 kernel_size=(3, 3), stride=(1, 1),
                                 padding=(1, 1), bias=False)
                                         (bn1): BatchNorm2d(640,
                                 eps=1e-05, momentum=0.1,
                                 affine=True,
                                 track_running_stats=True)
                                         (relu):
                                 LeakyReLU(negative_slope=0.1)
                                         (conv2): Conv2d(640, 640,
                                 kernel_size=(3, 3), stride=(1, 1),
                                 padding=(1, 1), bias=False)
                                         (bn2): BatchNorm2d(640,
                                 eps=1e-05, momentum=0.1,
                                 affine=True,
                                 track_running_stats=True)
                                         (conv3): Conv2d(640, 640,
                                 kernel_size=(3, 3), stride=(1, 1),
                                 padding=(1, 1), bias=False)
                                         (bn3): BatchNorm2d(640,
                                 eps=1e-05, momentum=0.1,
                                 affine=True,
                                 track_running_stats=True)
                                         (maxpool):
                                 MaxPool2d(kernel_size=2, stride=2,
                                 padding=0, dilation=1,
                                 ceil_mode=False)
                                         (downsample): Sequential(
                                           (0): Conv2d(320, 640,
                                 kernel_size=(1, 1), stride=(1, 1),
                                 bias=False)
                                           (1): BatchNorm2d(640,
                                 eps=1e-05, momentum=0.1,
                                 affine=True,
                                 track_running_stats=True)
                                         )
                                         (DropBlock): DropBlock()
                                       )
                                     )
                                     (avgpool):
                                 AvgPool2d(kernel_size=5, stride=1,
                                 padding=0)
                                     (dropout): Dropout(p=0.0,
                                 inplace=False)
                                   )
                                   (cam_layer): CAMLayer(
                                     (cam): CAM(
                                       (conv1): ConvBlock(
                                         (conv): Conv2d(100, 10,
                                 kernel_size=(1, 1), stride=(1, 1))
                                         (bn): BatchNorm2d(10,
                                 eps=1e-05, momentum=0.1,
                                 affine=True,
                                 track_running_stats=True)
                                       )
                                       (conv2): Conv2d(10, 100,
                                 kernel_size=(1, 1), stride=(1, 1))
                                     )
                                     (classifier): Conv2d(64, 64,
                                 kernel_size=(1, 1), stride=(1, 1))
                                   )
                                   (loss_func): CrossEntropyLoss(
                                     (logsoftmax): LogSoftmax(dim=1)
                                   )
                                 )
                        INFO     Trainable params in the model:       trainer.py:357
                                 12430610
    [11/18/21 12:49:45] INFO     load 38400 image with 64 label.       dataset.py:94
                        INFO     load 9600 image with 16 label.        dataset.py:94
                        INFO     load 12000 image with 20 label.       dataset.py:94
                        INFO     Adam (                               trainer.py:447
                                 Parameter Group 0
                                     amsgrad: False
                                     betas: (0.9, 0.999)
                                     eps: 1e-08
                                     initial_lr: 0.001
                                     lr: 0.001
                                     weight_decay: 0
    
                                 Parameter Group 1
                                     amsgrad: False
                                     betas: (0.9, 0.999)
                                     eps: 1e-08
                                     initial_lr: 0.001
                                     lr: 0.001
                                     weight_decay: 0
                                 )
                        INFO     ============ Train on the train set   trainer.py:67
                                 ============
    Traceback (most recent call last):
      File "/src/run_trainer.py", line 12, in <module>
        trainer.train_loop()
      File "/src/core/trainer.py", line 68, in train_loop
        train_acc = self._train(epoch_idx)
      File "/src/core/trainer.py", line 143, in _train
        output, acc, loss = self.model.set_forward_loss(batch)
      File "/src/core/model/metric/can.py", line 413, in set_forward_loss
        support_feat, query_feat, support_targets_one_hot, query_targets_one_hot
      File "/opt/conda/lib/python3.7/site-packages/torch/nn/modules/module.py", line 1102, in _call_impl
        return forward_call(*input, **kwargs)
      File "/src/core/model/metric/can.py", line 214, in forward
        prototypes, query_feat
      File "/opt/conda/lib/python3.7/site-packages/torch/nn/modules/module.py", line 1102, in _call_impl
        return forward_call(*input, **kwargs)
      File "/src/core/model/metric/can.py", line 149, in forward
        a1 = self.get_attention(a1)  # [1, 5, 75, 36]
      File "/src/core/model/metric/can.py", line 119, in get_attention
        a = F.relu(self.conv1(a))
      File "/opt/conda/lib/python3.7/site-packages/torch/nn/modules/module.py", line 1102, in _call_impl
        return forward_call(*input, **kwargs)
      File "/src/core/model/metric/can.py", line 92, in forward
        return self.bn(self.conv(x))
      File "/opt/conda/lib/python3.7/site-packages/torch/nn/modules/module.py", line 1102, in _call_impl
        return forward_call(*input, **kwargs)
      File "/opt/conda/lib/python3.7/site-packages/torch/nn/modules/conv.py", line 446, in forward
        return self._conv_forward(input, self.weight, self.bias)
      File "/opt/conda/lib/python3.7/site-packages/torch/nn/modules/conv.py", line 443, in _conv_forward
        self.padding, self.dilation, self.groups)
    RuntimeError: Given groups=1, weight of size [10, 100, 1, 1], expected input[2, 289, 75, 5] to have 100 channels, but got 289 channels instead
    
    opened by AlephNullVEVO 3
Owner
VIG@R&L
Visual Intelligence Group (VIG), Reasoning and Learning Research Group, Nanjing University.
VIG@R&L
Few-NERD: Not Only a Few-shot NER Dataset

Few-NERD: Not Only a Few-shot NER Dataset This is the source code of the ACL-IJCNLP 2021 paper: Few-NERD: A Few-shot Named Entity Recognition Dataset.

THUNLP 319 Dec 30, 2022
Library of various Few-Shot Learning frameworks for text classification

FewShotText This repository contains code for the paper A Neural Few-Shot Text Classification Reality Check Environment setup # Create environment pyt

Thomas Dopierre 47 Jan 3, 2023
Pytorch Implementation for CVPR2018 Paper: Learning to Compare: Relation Network for Few-Shot Learning

LearningToCompare Pytorch Implementation for Paper: Learning to Compare: Relation Network for Few-Shot Learning Howto download mini-imagenet and make

Jackie Loong 246 Dec 19, 2022
Few-shot Learning of GPT-3

Few-shot Learning With Language Models This is a codebase to perform few-shot "in-context" learning using language models similar to the GPT-3 paper.

Tony Z. Zhao 224 Dec 28, 2022
Few-Shot Graph Learning for Molecular Property Prediction

Few-shot Graph Learning for Molecular Property Prediction Introduction This is the source code and dataset for the following paper: Few-shot Graph Lea

Zhichun Guo 94 Dec 12, 2022
Few-shot Relation Extraction via Bayesian Meta-learning on Relation Graphs

Few-shot Relation Extraction via Bayesian Meta-learning on Relation Graphs This is an implemetation of the paper Few-shot Relation Extraction via Baye

MilaGraph 36 Nov 22, 2022
True Few-Shot Learning with Language Models

This codebase supports using language models (LMs) for true few-shot learning: learning to perform a task using a limited number of examples from a single task distribution.

Ethan Perez 124 Jan 4, 2023
Adaptive Prototype Learning and Allocation for Few-Shot Segmentation (CVPR 2021)

ASGNet The code is for the paper "Adaptive Prototype Learning and Allocation for Few-Shot Segmentation" (accepted to CVPR 2021) [arxiv] Overview data/

Gen Li 91 Dec 23, 2022
Code for 'Self-Guided and Cross-Guided Learning for Few-shot segmentation. (CVPR' 2021)'

SCL Introduction Code for 'Self-Guided and Cross-Guided Learning for Few-shot segmentation. (CVPR' 2021)' We evaluated our approach using two baseline

null 34 Oct 8, 2022
Spatial Contrastive Learning for Few-Shot Classification (SCL)

This repo contains the official implementation of Spatial Contrastive Learning for Few-Shot Classification (SCL), which presents of a novel contrastive learning method applied to few-shot image classification in order to learn more general purpose embeddings, and facilitate the test-time adaptation to novel visual categories.

Yassine 34 Dec 25, 2022
Prototypical Networks for Few shot Learning in PyTorch

Prototypical Networks for Few shot Learning in PyTorch Simple alternative Implementation of Prototypical Networks for Few Shot Learning (paper, code)

Orobix 835 Jan 8, 2023
Pytorch implementation of the paper "Optimization as a Model for Few-Shot Learning"

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.

Albert Berenguel Centeno 238 Jan 4, 2023
Implementation of the paper "Self-Promoted Prototype Refinement for Few-Shot Class-Incremental Learning"

Self-Promoted Prototype Refinement for Few-Shot Class-Incremental Learning This is the implementation of the paper "Self-Promoted Prototype Refinement

Kai Zhu 78 Dec 2, 2022
Simple and Effective Few-Shot Named Entity Recognition with Structured Nearest Neighbor Learning

structshot Code and data for paper "Simple and Effective Few-Shot Named Entity Recognition with Structured Nearest Neighbor Learning", Yi Yang and Arz

ASAPP Research 47 Dec 27, 2022
Audio-Visual Generalized Few-Shot Learning with Prototype-Based Co-Adaptation

Audio-Visual Generalized Few-Shot Learning with Prototype-Based Co-Adaptation The code repository for "Audio-Visual Generalized Few-Shot Learning with

Kaiaicy 3 Jun 27, 2022
The Few-Shot Bot: Prompt-Based Learning for Dialogue Systems

Few-Shot Bot: Prompt-Based Learning for Dialogue Systems This repository includes the dataset, experiments results, and code for the paper: Few-Shot B

Andrea Madotto 103 Dec 28, 2022
This repository is the code of the paper "Sparse Spatial Transformers for Few-Shot Learning".

?? Sparse Spatial Transformers for Few-Shot Learning This code implements the Sparse Spatial Transformers for Few-Shot Learning(SSFormers). Our code i

chx_nju 38 Dec 13, 2022
Task-related Saliency Network For Few-shot learning

Task-related Saliency Network For Few-shot learning This is an official implementation in Tensorflow of TRSN. Abstract An essential cue of human wisdo

null 1 Nov 18, 2021
mmfewshot is an open source few shot learning toolbox based on PyTorch

OpenMMLab FewShot Learning Toolbox and Benchmark

OpenMMLab 514 Dec 28, 2022