Git Product home page Git Product logo

dsn_fewshot's Introduction

Adaptive Subspaces for Few-Shot Learning

The repository contains the code for:
Adaptive Subspaces for Few-Shot Learning
CVPR 2020

Our pipeline:

Comparison with previous methods:

Robustness on toy data: subspaces VS prototypes

OVERVIEW

Requirements:

  • PyTorch 1.0 or above
  • Python 3.6

There are two backbones separated in different folders.

  • Conv-4, there are two datasets using this backbone: mini-ImageNet and OpenMIC.
  • ResNet-12, there are three datasets using this backbone: mini-ImageNet, tiered-ImageNet, and Cifar-FS.

DATASET

** Adopted from Kwonjoon Lee

Pretrained network

Pretrained Models

USAGE

Conv-4

Train mini-ImageNet:

python3 train_subspace_discriminative.py --data-path 'yourdatafolder'

Evaluate mini-ImageNet:

python3 test_subspace_discriminative.py --data-path 'yourdatafolder'

Train OpenMIC:

python3 train_subspace_museum.py --data-path 'yourdatafolder'

ResNet-12

Note: Training using ResNet-12 requires 4 GPUs with ~10GB/GPU

Set the image folders:

_IMAGENET_DATASET_DIR = './miniimagenet/' (in data/mini_imagenet.py)
_TIERED_IMAGENET_DATASET_DIR = '/tieredimagenet/' (in data/tiered_imagenet.py)
_CIFAR_FS_DATASET_DIR = './cifar/CIFAR-FS/' (in data/CIFAR_FS.py)

Train mini-ImageNet:

  python3 train.py --gpu 0,1,2,3 --save-path "./experiments/miniImageNet_subspace" --train-shot 15 --\
  --head Subspace --network ResNet --dataset miniImageNet --eps 0.1

Evaluate mini-ImageNet:

  python3 test.py --gpu 0 --load ./experiments/miniImageNet_subspace/best_model.pth --episode 1000 \
  --way 5 --shot 5 --query 15 --head Subspace --network ResNet --dataset miniImageNet
options --dataset [miniImageNet, tieredImageNet, CIFAR_FS]

Citation:

@inproceedings{simon2020dsn,
        author       = {C. Simon}, {P. Koniusz}, {R. Nock}, and {M. Harandi}
        title        = {Adaptive Subspaces for Few-Shot Learning},
        booktitle    = {The IEEE Conference on Computer Vision and Pattern Recognition (CVPR)}
        year         = 2020
        }

Acknowledgement

Thank you for the codebases:

Prototypical Network

MetaOpt

dsn_fewshot's People

Contributors

chrysts avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

dsn_fewshot's Issues

Question for test_subspace_discriminative.py

Hi, thanks for your work, it's very inspiring to me.
i used the dataset and pretrained model provided in attached files, but i can't reproduce the results by running the test_subspace_discirminative.py file. Also in the line 95 and 96, the trlog doesn't have the attribute 'val_loss' and 'val_acc'

tieredImagenet loader meet a problem ,the dict don't have attribute labels ,it have label_general and label_specific?

1 As the tilte , I run the program for the tieredImagenet ,but I met the problem at the data_train['labels'] , then i debug and find that the data_train don't have labels attribute, but it have label_general and label_specific, do you meet the problem or you have any ideas about this? by the way ,the data you provide is about 12GB, I found another 23GB data and it works. Why the data you give have the label_general and label_specific problem?

2 thank you for your work, the mini-imagenet and the tieredImagenet you give the learning rate, could you give the learning rate for cifar fs.
@chrysts look forward you reply sincerly!

The val and test set problem in ResNet-12 mini-Imagenet experiment.

Thanks for sharing your excellent works!
I have some questions when I reproduce the results of ProtoNet using ResNet-12:

  1. In mini-Imagenet experiments of Resnet12, why you load the val dataset in train.py (line 84) use “phase=test", which I think it should be “phase=val", or the val dataset will be same with the test dataset in test.py (line 91).
  2. In your code, it seems that the test dataset and val dataset loaded from the pickle file include some base categories (training data). Dose it cause the data leakage problem?

Thank you very much!

I trained the tired-Imagnet with protonet,used resnet12,bu the accuracy test is only 78.4,less than 80,so whats the parameters?

Thank you for your reply for the two issues.
I have another question, I used the 10-shot 5-way to train, and tested the 5-shot, but only get 78.4,could you tell me the paramerts, like the learning rates, my learning rates is lambda_epoch = lambda e: 1.0 if e < 20 else (0.012 if e < 45 else 0.0052 if e < 59 else (0.00054 if e < 68 else (0.00012))),
Are there any other paramerts need to ajust? or how to train and test to get the 80.00 accuracy for the tired-imagnet.
Thank you very much.

Dataset mini-ImageNet - ResNet12 link issue.

Fisrtly, thanks for your research, which inspire me a lot.
While I'm tryin to reproduce the result of miniImageNet on ResNet12, the links seems fail and cannot downloads it.
Is there any solution for this, thanks.

tensors in double for SVD

Hi!
Thanks for sharing the code.
I noticed that you converted the tensor to double before fedding to torch.svd
May I ask why you have this implementation?
Thanks!

CUDA error: an illegal memory access was encountered

Hi!
Thanks for sharing the code.
When running the conv4 experiment using the python train_subspace_discriminative.py --data-path /home/dsn_fewshot/miniImageNet command, I encountered an error as follows:

acc = count_acc(logits, label)
File "/home/dsn_fewshot/Conv4/utils.py", line 86, in count_acc
return (pred == label).type(torch.cuda.FloatTensor).mean().item()
RuntimeError: CUDA error: an illegal memory access was encountered

In debug mode, I locate this error appearing in line 43 in the subspace_projection.py file,that is,
projected_query_j = torch.bmm(h_plane_j, torch.bmm(torch.transpose(h_plane_j, 1, 2), target_features_expanded) ,
and the error is Unable to get repr for<class‘torch.Tensor‘>

Could you tell me how to solve this problem?

Can't run ResNet-12 experiments

Hi,

After downloading the datasets as suggested in the README file, I cannot run the ResNet-12 experiments (Conv4 experiments do run however).

Here are the commands and the output I get:

python3 train.py --train-shot 15 --head Subspace --network ResNet --dataset miniImageNet --eps 0.1

Loading mini ImageNet dataset - phase trainval
Traceback (most recent call last):
File "/home/src/dsn_fewshot/Resnet12/data/mini_imagenet.py", line 45, in load_data
with open(file, 'rb') as fo:
FileNotFoundError: [Errno 2] No such file or directory: '/home/mini-imagenet/miniImageNet_category_split_train_phase_train.pickle'

python3 train.py --train-shot 15 --head Subspace --network ResNet --dataset tieredImageNet --eps 0.1
Loading tiered ImageNet dataset - phase train
Traceback (most recent call last):
File "train.py", line 135, in
(dataset_train, dataset_val, data_loader) = get_dataset(opt)
File "train.py", line 83, in get_dataset
dataset_train = tieredImageNet(phase='train')
File "/home/src/dsn_fewshot/Resnet12/data/tiered_imagenet.py", line 100, in init
self.labels = data_train['labels']
KeyError: 'labels'

Which copies of mini-imagenet and tiered-imagenet have you used for your ResNet-12 experiments? The Mini-Imagenet dataset that you have pointed in the README does not contain any pickle files.

About discriminative loss.

Hi, thanks for your work.

I notice that there is a discriminative loss in section 4.4 of your paper, but i didn't find it in your code when using resnet12 as the backbone.

Should I add this loss if I want to reproduce the results of resnet12 in your paper?

Question about Equation 2 and its implementation

Hi, thanks for your work, it's very inspiring to me.
But I‘m confused about how Equation2 is derived. Could you please give me some promts about how this formula is derived?
And I notice that there is an identity matrix I in this formula, but it seems that the code implementation does not have it. I also don't quite understand how it's implemented here.
Thanks.

Test on the miniimagenet dataset

Hello, thanks for your great work first.
When I run the test_subspace_discriminative in Conv4 on the miniimagenet dataset. The result is that:

{'data_path': '/media/ubuntu/460CFEF50CFEDEBD/wl/CovaMNet-master/dataset/mini-imagenet/For_FewShot/',
 'gpu': '0',
 'lamb': 5,
 'max_epoch': 600,
 'query': 15,
 'save_epoch': 100,
 'save_path': './save/subspace-5w5sdiscriminative/max-acc.pth',
 'shot': 1,
 'subspace_dim': 0,
 'test_way': 5,
 'train_way': 5}
using gpu: 0
 TEST loss=1.2516 acc=0.4917 maxacc=0.0000

I want to know if this result is correct, or what other parameters I need to add during the run.
Thanks in advance for your help.

The setting of '--train-shot' in ResNet12/train.py

Hi! Thanks for the great work.

Does the parameter '--train-shot' in ResNet12/train.py mean K-shot during meta-training? And when I set this parameter as 1, the network seems to do not converge and the ACC always is 20%, however, the network can be trained successfully when it is 15.

How to reproduce the reported results?

I am trying to reproduce the results in the paper, and I tried to run the scripts in the Conv4 dir with default parameters, but the results are not as good as the reported ones in the paper. Could you share the parameters and more training details? That can be very helpful for me and I really appreciate it.

DSN for CUB dataset

Hi,
Using your code, i can reproduce the results on your paper.
Then i try to use DSN to train on the CUB-200-2011 dataset, but I got the error "The algorithm failed to converge because the input matrix is ill-conditioned or has too many repeated singular values".
Are there any solutions to this issue? BTW, I used the common data format of CUB, which contains the raw images with different resolutions.

Thank you in advance.

Issue on subspace dimension

Hi. In Conv4/train_subspace_discriminative.py, Subspace_Projection is initialized before the args.subspace_dim is assigned, which in the case of 1-shot results in the subspace dimension being set to 0. This seems to be inconsistent with the paper.

Looking forward to your reply!

a request

Sorry to bother you, is your email still [email protected]? I can get in touch with you via email, but it keeps failing, I don’t know why。

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.