Giter Club home page Giter Club logo

libfewshot's Issues

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

CUB Dataset issue

The link of CUB dataset is no longer valid. The dataset was moved to [https://data.caltech.edu/records/20098]

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'

tieredimagenet

There is some error with the tieredimagenet dataset, gz01 is a compressed package, but gz02 and gz03 are binary files. Is it right?

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.

Number of classes is below way_num settings

Hello, I'm using a custom dataset to train data with 12 classes and test with 2 classes only. I assumed that test set would have higher accuracy initially because of less choices. However, test accuracy got stuck to 0. I think the problem is because way_num = 5.

Maybe one of the following can be done to avoid confusion on the accuracy:

  • Add warning message that number of classes is below way_num
  • Reduce the way_num to number of classes if way_num is higher

What do you think can be done?

batch = torch.stack(batch).reshape(-1)

请问在训练自己数据集时报错:
/LibFewShot-main/core/data/samplers.py", line 64, in iter batch = torch.stack(batch).reshape(-1)
RuntimeError: stack expects each tensor to be equal size, but got [16] at entry 0 and [4] at entry 4
应该怎样解决呢

Result of ProtoNet with conv64F on miniImageNet

Thanks for sharing the codes and your excellent work.
In Table 2, I see ProtoNet using Conv64F backbone achieved 72% accuracy on miniImageNet 5-way 5-shot setting. However, since ProtoNet did not use data augmentation, my guess is that the possible reason lies in the use of center crop on the meta-test dataset for evalution. Can you explain how you got this result?
Thanks!

关于LEO的复现

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

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

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

在headers里面是否缺少一个losses.yaml。

作者大大,你好,在headers里面是否缺少一个losses.yaml呢?在准备数据集(以miniImagenet为例)的例子中,你们采用了ProtoNet为例,需要新写一个yaml文件getting_started.yaml,在getting_started.yaml文件中有一个losses.yaml,但在我们下载的headers文件里并没有losses.yaml文件。

复现问题

作者您好,我在自己的环境下尝试在miniimagenet上跑了LibFewShot中的部分代码,除了修改了dataset的目录外均采用您的默认设置,但跑出的结果比您论文中的结果少了很多。比如我跑了DN4算法,除了修改shot数量,别的都没有改,跑出来的结果如下:

方法 5way 1shot (our/paper) 5way 5shot (our/paper)
dn4 45.667/51.95 57.947/71.42
proto 30.72/46.30 37.220/66.24
versa 23.12/51.92 30.133 /66.26
R2d2 34.640/47.57 57.040/66.68
在论文中您提到了训练dn4的时候在训练阶段使用了数据增广,但并没有找到具体的增广数量。 请问这些详细的超参数设置应该怎么设置呢?

code

Hello, there are several methods that run code with errors, such as relation, maml, mtl, leo, etc. And several methods to change the embedding backbone also have errors.

在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)

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?

CAN模型的特征维度不匹配

你好,感谢你们团队在fsl的贡献,我在使用CAN模型的resnet12backbone时,出现特征维度不匹配的问题
RuntimeError: Given groups=1, weight of size [10, 100, 1, 1], expected input[4, 289, 3, 3] to have 100 channels, but got 289 channels instead
定位报错的部分应该是LibFewShot/core/model/metric/can.py的line138和line114
File "/home/x015/Project/LibFewShot/core/model/metric/can.py", line 138, in forward a1 = self.get_attention(a1) # [1, 5, 75, 36] File "/home/x015/Project/LibFewShot/core/model/metric/can.py", line 114, in get_attention a = F.relu(self.conv1(a))
我在can.yaml配置文件中修改为这样
`includes:

  • headers/data.yaml
  • headers/device.yaml
  • headers/misc.yaml
  • headers/model.yaml
  • headers/optimizer.yaml
  • classifiers/CAN.yaml
  • backbones/resnet12.yaml

episode_size: 4

classifier:
name: CAN
kwargs:
scale_cls: 7 # default
num_class: 64
nFeat: 64
HW: 10

backbone:
name: resnet12
kwargs:
maxpool_last2: False
is_flatten: False
`
请问forward过程中的特征维度怎么修改为符合模型的size

另data.yaml无修改
model.yaml将5way-1shot改为3way-1shot batch_size改为64

the default setting of CAN get wrong validation and testing acc

dataset: miniImageNet 5way 1shot
use the default config of config/can.yaml
the value of validation and testing Acc too too big and dont know why

log:
2021-11-09 16:24:37,061 [INFO] core.trainer: {'data_root': '/media/xaserver/DATA/xxx/LibFewShot/data/miniImageNet', 'image_size': 84, 'use_memory': False, 'augment': True, 'augment_times': 1, 'augment_times_query': 1, 'device_ids': 1, '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': 4, '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': 'Conv64F', 'kwargs': {'is_flatten': False, 'is_feature': False, 'leaky_relu': True, 'negative_slope': 0.2, 'last_pool': False}}, 'tb_scale': 1.0}
2021-11-09 16:24:37,097 [INFO] core.trainer: CAN(
(emb_func): Conv64F(
(layer1): Sequential(
(0): Conv2d(3, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
(1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(2): LeakyReLU(negative_slope=0.2, inplace=True)
(3): MaxPool2d(kernel_size=2, stride=2, padding=0, dilation=1, ceil_mode=False)
)
(layer2): Sequential(
(0): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
(1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(2): LeakyReLU(negative_slope=0.2, inplace=True)
(3): MaxPool2d(kernel_size=2, stride=2, padding=0, dilation=1, ceil_mode=False)
)
(layer3): Sequential(
(0): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
(1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(2): LeakyReLU(negative_slope=0.2, inplace=True)
)
(layer3_maxpool): MaxPool2d(kernel_size=2, stride=2, padding=0, dilation=1, ceil_mode=False)
(layer4): Sequential(
(0): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
(1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(2): LeakyReLU(negative_slope=0.2, inplace=True)
)
(layer4_pool): MaxPool2d(kernel_size=2, stride=2, padding=0, dilation=1, ceil_mode=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)
)
)
2021-11-09 16:24:37,159 [INFO] core.trainer: Trainable params in the model: 119378
2021-11-09 16:24:42,820 [INFO] core.data.dataset: load 38400 image with 64 label.
2021-11-09 16:24:42,853 [INFO] core.data.dataset: load 9600 image with 16 label.
2021-11-09 16:24:42,877 [INFO] core.data.dataset: load 12000 image with 20 label.
2021-11-09 16:24:42,885 [INFO] core.trainer: Adam (
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
)
2021-11-09 16:24:42,899 [INFO] core.trainer: ============ Train on the train set ============
2021-11-09 16:25:02,934 [INFO] core.trainer: Epoch-(0): [100/100] Time 0.359 (0.801) Calc 0.126 (0.118) Data 0.073 (0.543) Loss 5.020 (5.060) Acc@1 33.333 (30.907)
2021-11-09 16:25:02,941 [INFO] core.trainer: * Acc@1 30.907
2021-11-09 16:25:02,943 [INFO] core.trainer: ============ Validation on the val set ============
2021-11-09 16:25:22,238 [INFO] core.trainer: Epoch-(0): [100/100] Time 0.185 (0.771) Calc 0.033 (0.045) Data 0.149 (0.723) Acc@1 2375.000 (2008.000)
2021-11-09 16:25:22,252 [INFO] core.trainer: * Acc@1 2008.000 Best acc -inf
2021-11-09 16:25:22,255 [INFO] core.trainer: ============ Testing on the test set ============
2021-11-09 16:25:43,216 [INFO] core.trainer: Epoch-(0): [100/100] Time 0.156 (0.837) Calc 0.037 (0.036) Data 0.117 (0.796) Acc@1 2225.000 (2009.000)
2021-11-09 16:25:43,221 [INFO] core.trainer: * Acc@1 2009.000 Best acc -inf
2021-11-09 16:25:43,222 [INFO] core.trainer: * Time: 0:01:00/0:50:00
2021-11-09 16:25:43,237 [INFO] core.trainer: ============ Train on the train set ============
2021-11-09 16:26:02,739 [INFO] core.trainer: Epoch-(1): [100/100] Time 0.324 (0.779) Calc 0.126 (0.091) Data 0.096 (0.579) Loss 4.887 (4.945) Acc@1 36.333 (33.760)
2021-11-09 16:26:02,745 [INFO] core.trainer: * Acc@1 33.760
2021-11-09 16:26:02,747 [INFO] core.trainer: ============ Validation on the val set ============
2021-11-09 16:26:19,315 [INFO] core.trainer: Epoch-(1): [100/100] Time 0.129 (0.662) Calc 0.051 (0.066) Data 0.075 (0.594) Acc@1 2375.000 (2306.000)
2021-11-09 16:26:19,320 [INFO] core.trainer: * Acc@1 2306.000 Best acc 2008.000
2021-11-09 16:26:19,322 [INFO] core.trainer: ============ Testing on the test set ============
2021-11-09 16:26:37,707 [INFO] core.trainer: Epoch-(1): [100/100] Time 0.146 (0.735) Calc 0.066 (0.051) Data 0.079 (0.680) Acc@1 2175.000 (2322.000)
2021-11-09 16:26:37,712 [INFO] core.trainer: * Acc@1 2322.000 Best acc 2009.000
2021-11-09 16:26:37,714 [INFO] core.trainer: * Time: 0:01:54/0:47:30
2021-11-09 16:26:37,732 [INFO] core.trainer: ============ Train on the train set ============
2021-11-09 16:26:55,620 [INFO] core.trainer: Epoch-(2): [100/100] Time 0.322 (0.715) Calc 0.065 (0.109) Data 0.086 (0.460) Loss 4.910 (4.890) Acc@1 29.000 (33.613)
2021-11-09 16:26:55,626 [INFO] core.trainer: * Acc@1 33.613
2021-11-09 16:26:55,628 [INFO] core.trainer: ============ Validation on the val set ============
2021-11-09 16:27:15,458 [INFO] core.trainer: Epoch-(2): [100/100] Time 0.155 (0.792) Calc 0.041 (0.038) Data 0.111 (0.751) Acc@1 2025.000 (2292.000)
2021-11-09 16:27:15,466 [INFO] core.trainer: * Acc@1 2292.000 Best acc 2306.000
2021-11-09 16:27:15,473 [INFO] core.trainer: ============ Testing on the test set ============
2021-11-09 16:27:36,929 [INFO] core.trainer: Epoch-(2): [100/100] Time 0.113 (0.857) Calc 0.033 (0.037) Data 0.075 (0.816) Acc@1 2200.000 (2457.000)
2021-11-09 16:27:36,942 [INFO] core.trainer: * Acc@1 2457.000 Best acc 2322.000
2021-11-09 16:27:36,945 [INFO] core.trainer: * Time: 0:02:54/0:48:20
2021-11-09 16:27:36,966 [INFO] core.trainer: ============ Train on the train set ============
2021-11-09 16:27:56,671 [INFO] core.trainer: Epoch-(3): [100/100] Time 0.304 (0.787) Calc 0.138 (0.097) Data 0.078 (0.574) Loss 4.713 (4.866) Acc@1 37.667 (34.227)
2021-11-09 16:27:56,676 [INFO] core.trainer: * Acc@1 34.227
2021-11-09 16:27:56,678 [INFO] core.trainer: ============ Validation on the val set ============
2021-11-09 16:28:13,848 [INFO] core.trainer: Epoch-(3): [100/100] Time 0.168 (0.686) Calc 0.080 (0.060) Data 0.086 (0.623) Acc@1 2025.000 (2376.000)
2021-11-09 16:28:13,854 [INFO] core.trainer: * Acc@1 2376.000 Best acc 2306.000
2021-11-09 16:28:13,857 [INFO] core.trainer: ============ Testing on the test set ============
2021-11-09 16:28:31,461 [INFO] core.trainer: Epoch-(3): [100/100] Time 0.133 (0.703) Calc 0.058 (0.053) Data 0.071 (0.648) Acc@1 2075.000 (2496.000)
2021-11-09 16:28:31,469 [INFO] core.trainer: * Acc@1 2496.000 Best acc 2322.000
2021-11-09 16:28:31,472 [INFO] core.trainer: * Time: 0:03:48/0:47:30
2021-11-09 16:28:31,494 [INFO] core.trainer: ============ Train on the train set ============
2021-11-09 16:28:50,966 [INFO] core.trainer: Epoch-(4): [100/100] Time 0.314 (0.778) Calc 0.120 (0.101) Data 0.057 (0.550) Loss 4.886 (4.818) Acc@1 30.667 (34.667)
2021-11-09 16:28:50,971 [INFO] core.trainer: * Acc@1 34.667
2021-11-09 16:28:50,973 [INFO] core.trainer: ============ Validation on the val set ============
2021-11-09 16:29:09,167 [INFO] core.trainer: Epoch-(4): [100/100] Time 0.207 (0.727) Calc 0.035 (0.048) Data 0.160 (0.675) Acc@1 1950.000 (2253.000)
2021-11-09 16:29:09,183 [INFO] core.trainer: * Acc@1 2253.000 Best acc 2376.000
2021-11-09 16:29:09,195 [INFO] core.trainer: ============ Testing on the test set ============
2021-11-09 16:29:29,702 [INFO] core.trainer: Epoch-(4): [100/100] Time 0.119 (0.819) Calc 0.032 (0.036) Data 0.085 (0.778) Acc@1 2450.000 (2397.000)
2021-11-09 16:29:29,706 [INFO] core.trainer: * Acc@1 2397.000 Best acc 2496.000
2021-11-09 16:29:29,708 [INFO] core.trainer: * Time: 0:04:46/0:47:40
2021-11-09 16:29:29,718 [INFO] core.trainer: ============ Train on the train set ============
2021-11-09 16:29:53,272 [INFO] core.trainer: Epoch-(5): [100/100] Time 0.389 (0.941) Calc 0.143 (0.096) Data 0.093 (0.760) Loss 4.827 (4.791) Acc@1 32.000 (35.253)
2021-11-09 16:29:53,277 [INFO] core.trainer: * Acc@1 35.253
2021-11-09 16:29:53,279 [INFO] core.trainer: ============ Validation on the val set ============
2021-11-09 16:30:08,510 [INFO] core.trainer: Epoch-(5): [100/100] Time 0.136 (0.608) Calc 0.052 (0.063) Data 0.081 (0.543) Acc@1 2825.000 (2448.000)
2021-11-09 16:30:08,514 [INFO] core.trainer: * Acc@1 2448.000 Best acc 2376.000
2021-11-09 16:30:08,516 [INFO] core.trainer: ============ Testing on the test set ============
2021-11-09 16:30:22,733 [INFO] core.trainer: Epoch-(5): [100/100] Time 0.154 (0.568) Calc 0.033 (0.060) Data 0.119 (0.505) Acc@1 2300.000 (2481.000)
2021-11-09 16:30:22,739 [INFO] core.trainer: * Acc@1 2481.000 Best acc 2496.000
2021-11-09 16:30:22,741 [INFO] core.trainer: * Time: 0:05:39/0:47:05

I config as this yaml file './reproduce/RENet/RENet-miniImageNet--ravi-Conv64F-5-5-Table2.yaml'. It runs with errors as below.

2023-01-05 06:32:28,367 [INFO] core.trainer: ============ Train on the train set ============
2023-01-05 06:32:28,368 [INFO] core.trainer: learning rate: [0.1, 0.1]
Traceback (most recent call last):
File "/home/liuxuanchen/Develop/meta-learning/LibFewShot/run_trainer.py", line 29, in
main(0, config)
File "/home/liuxuanchen/Develop/meta-learning/LibFewShot/run_trainer.py", line 14, in main
trainer.train_loop(rank)
File "/home/liuxuanchen/Develop/meta-learning/LibFewShot/core/trainer.py", line 83, in train_loop
train_acc = self._train(epoch_idx)
File "/home/liuxuanchen/Develop/meta-learning/LibFewShot/core/trainer.py", line 169, in _train
output, acc, loss = self.model(
File "/home/liuxuanchen/anaconda3/envs/torch1.13/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1194, in _call_impl
return forward_call(*input, **kwargs)
File "/home/liuxuanchen/Develop/meta-learning/LibFewShot/core/model/abstract_model.py", line 30, in forward
return self.set_forward_loss(x)
File "/home/liuxuanchen/Develop/meta-learning/LibFewShot/core/model/finetuning/renet.py", line 410, in set_forward_loss
(
ValueError: not enough values to unpack (expected 4, got 2)
Exception in thread Thread-2:
Traceback (most recent call last):
File "/home/liuxuanchen/anaconda3/envs/torch1.13/lib/python3.9/threading.py", line 980, in _bootstrap_inner
self.run()
File "/home/liuxuanchen/anaconda3/envs/torch1.13/lib/python3.9/threading.py", line 917, in run
self._target(*self._args, **self._kwargs)
File "/home/liuxuanchen/anaconda3/envs/torch1.13/lib/python3.9/site-packages/torch/utils/data/_utils/pin_memory.py", line 49, in _pin_memory_loop
do_one_step()
File "/home/liuxuanchen/anaconda3/envs/torch1.13/lib/python3.9/site-packages/torch/utils/data/_utils/pin_memory.py", line 26, in do_one_step
r = in_queue.get(timeout=MP_STATUS_CHECK_INTERVAL)
File "/home/liuxuanchen/anaconda3/envs/torch1.13/lib/python3.9/multiprocessing/queues.py", line 122, in get
return _ForkingPickler.loads(res)
File "/home/liuxuanchen/anaconda3/envs/torch1.13/lib/python3.9/site-packages/torch/multiprocessing/reductions.py", line 305, in rebuild_storage_fd
fd = df.detach()
File "/home/liuxuanchen/anaconda3/envs/torch1.13/lib/python3.9/multiprocessing/resource_sharer.py", line 57, in detach
with _resource_sharer.get_connection(self._id) as conn:
File "/home/liuxuanchen/anaconda3/envs/torch1.13/lib/python3.9/multiprocessing/resource_sharer.py", line 86, in get_connection
c = Client(address, authkey=process.current_process().authkey)
File "/home/liuxuanchen/anaconda3/envs/torch1.13/lib/python3.9/multiprocessing/connection.py", line 513, in Client
answer_challenge(c, authkey)
File "/home/liuxuanchen/anaconda3/envs/torch1.13/lib/python3.9/multiprocessing/connection.py", line 762, in answer_challenge
response = connection.recv_bytes(256) # reject large message
File "/home/liuxuanchen/anaconda3/envs/torch1.13/lib/python3.9/multiprocessing/connection.py", line 221, in recv_bytes
buf = self._recv_bytes(maxlength)
File "/home/liuxuanchen/anaconda3/envs/torch1.13/lib/python3.9/multiprocessing/connection.py", line 419, in _recv_bytes
buf = self._recv(4)
File "/home/liuxuanchen/anaconda3/envs/torch1.13/lib/python3.9/multiprocessing/connection.py", line 384, in _recv
chunk = read(handle, remaining)
ConnectionResetError: [Errno 104] Connection reset by peer

verbose

Thanks for sharing this code.
Is there any option to see the progress of training or live log display during training?

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!

检测结果可视化

首先感谢贵团队优秀的工作!但是在test阶段,该lib库好像只能显示平均检测精度和检测时间,并不能对检测结果可视化(无法进行类似目标检测的框出物体)也不能对每类的检测精度进行显示,请问后期贵团队有实现上述功能的计划吗?

For Baseline, Train in the trainset goes up to 300 while supposed to be 2000

Hi, I am evaluating the Baseline and ProtoNet with exactly the same setting while the train_episode: 2000 and test_episode: 2000. In ProtoNet the Train in the trainset goes up to 2000 in each epoch, but this up to 300 for the Baseline.
Is there any special setting I have accidentally set to 300?
Or it is as expected for the Baseline?

Config files to reproduce the paper's results

Hi, Thank you for your great job. Currently, I am reproducing the exact evaluations you have reported on the paper (especially Table 2). For sure it is easily reproducible from your complete tutorial, but I want to make sure I am going in exactly the right setting. So I will appreciate it if you can share the appropriate configs related to each table, If you already have them.

Protonet

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

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

datasets

Nice work. Could you please provide the relevant Download links to datasets?

pre-trained weights

Hey
I wanted to test a few of them "general pre trained" models in order to fine tune using my poor single GPU
Due to limits of hardware and time, I cannot reproduce the pre-trained results of the first stage, thus I cannot further analyze the performance of fine tuning.

Are you planning on releasing some of your checkpoint files?

Anyhow - great work, I love it and already use it a lot in my research. Keep on the good work

Questions about codes in can.py

Hi,

An error occurred when running the CAN model with 5way 5shot setting.
File "/LibFewShot-main/core/model/metric/can.py", line 381, in set_forward_loss episode_size, self.way_num RuntimeError: shape '[1, 5]' is invalid for input of size 25
I suppose the code here

https://github.com/RL-VIG/LibFewShot/blob/main/core/model/metric/can.py#L381

should be
support_targets = support_targets.reshape( episode_size, self.way_num * self.shot_num ).contiguous() .
Maybe there are other workarounds available?

Five time evaluation in Evaluation protocole

Hi, on section 3. Evaluation Settings and LibFewSh > Evaluation Protocols, it is stated that "we control the evaluation setting for all methods, evaluate them on 2000 sampled tasks and repeat this process five times, i.e., a total of 10000 tasks".
It seems you have used different seed values for each of these evaluations, I will appreciate it if you can share that five seeds list (the default is 0 now).
Or If all of them are evaluated with the same seed, I am wonder what will be the difference between five-time 2000 episodes and one-time 10000 episodes?

DeepBDC方法咨询

你好!首先感谢作者对代码库的不断更新,我最近试了下新增的DeepBDC方法,我按照reproduce中给的设置在miniImagenet上DeepBDC_pretrain(val type:stl)训练170epoch后,1-shot测试best_acc仅59.7,低于RFS的61.65,并且最后一个epoch的train_acc也才65.76。请问这是正常结果吗?
我在参考之前的RFS方法中的训练log文件时注意到在最后一个epoch的train_acc已经达到了99+。

Exact usage of 'way num' and 'test way'

Hello, I'm a junior deep learning researcher.

I'm using this library so well. By the way, I was testing a dataset with 10 classes and selected the 'way_num' and 'test_way' into 5 my mistake. There wasn't, however, an error. I saw the code and the two variables below are used for the layer. I guessed according to the num setting the result will be changed.

#54 (comment)

I was looking for a solution and found that answer in the issue of this repository. That says "if there are only 4 classes in your dataset, you should set way_num <=4". I thought that the number way_num is decided on N-way-M shot problem by the composition of a dataset. Would you explain the meaning and usage of "way_num" and how does it work while calculating accuracy?

Thank you so much.

maml方法似乎有个错误

在小循环里面,通过support data计算梯度,并更新参数到weith.fast。但是在计算episode_query_image的结果的时候,没有使用fast的参数,而是使用了默认self.parameters()的参数。(在MAMLLayer里面是直接return self.layers(x),在别的库里面似乎是F.linear(x, self.weight.fast, self.bias.fast))

LibFewShot学习使用过程中的一些困惑。

Discussed in #55

Originally posted by MasterWinston October 7, 2022

  1. ### 1.关于train、val、test set的困惑。

Libfewshot中把数据集分为train、val和test,比如,miniImagenet数据集有100个class,被分成train set、val set、test set;
但我看到在fewshot领域其他人对数据集处理时,似乎只分成了train set 和test set,也就是说100个class只需要分成不交叉的background 和evaluation(比如76:24), 而且就我对libfewshot代码中所理解的val on val set、test on test set部分,好像只是在train完后进行的两次重复性的test。
按照我从网上找到的对train、val和test的介绍,如下:
train是训练集,val是训练过程中的测试集,是为了让你在边训练边看到训练的结果,及时判断学习状态。test就是训练模型结束后,用于评价模型结果的测试集。
按我的理解,libfewshot在train阶段,val on val set、test on test set部分都是在边训练边看到训练的结果。是我的理解出了差错吗?

  1. ### 2.关于meta learning的一些疑惑。

据我了解,meta learning是在taskA、taskB、……上进行训练,然后在new task上进行少量的训练即可得到较好的结果。在miniImagenet上训练时的确也是按照这个思路来的,分成了train class和test class。现在假设我已经用miniImagenet训好了一个模型(5-way 5-shot)
然后如果我现在用自己的新的数据集,我是否可以直接使用libfewshot中的run_trainer_resume.py来进行训练呢?(假设之前的模型epoch:100,我想在训好的模型基础上训我自己的数据集10epoch,因此我在run_trainer_resume.py将epoch参数设为110,这个方法是否可行)。
另外,当这个数据集只有4 class且每个class的数据量只有4个时,我怎么在已经训好的模型(5-way 5-shot)上进行继续训练,还是说此时我无法使用这个训好的模型,只能先使用数据集,比如miniImagenet来重新训个4-way k(<4)-shot的模型呢?

hyperspectral images

Hi
Thanks for sharing this code.
Is it possible to use this library with images more than 3 channels for example hyper spectral images with 256 channels?

关于ReadMe中提供的百度网盘数据集似乎不能使用在这个框架下

我下载了百度网盘下面的miniimagenet,解压以后是pickle文件,并不是支持的格式。是不是其他的数据集也都需要自己去找呢。
dataset_folder/
├── images/
│ ├── images_1.jpg
│ ├── ...
│ └── images_n.jpg
├── train.csv *
├── test.csv *
└── val.csv *

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.