Coder Social home page Coder Social logo

wenbinlee / dn4 Goto Github PK

View Code? Open in Web Editor NEW
189.0 10.0 43.0 5.71 MB

Pytorch code of "Revisiting Local Descriptor based Image-to-Class Measure for Few-shot Learning", CVPR 2019.

License: Other

Python 100.00%
few-shot-learning local-descriptors image-to-class

dn4's People

Contributors

wenbinlee 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dn4's Issues

可视化

作者,您好。最近想在您的基础上,发表一篇小样本的论文,您方便提供一下可视化部分的代码吗?

about ablation study

thanks for your detailed code. I am not sure about the settings of DN4-IoI2 in paper 4.6. As the paper said,

DN4-IoI-2 restricts the search for the k-NN of a query’s local descriptor within each individual support image

in 5way5shot, if i understand right, lol-2 select top k local descriptors from one image pool instead from one class pool (as DN4 settings) for a query local descriptor, so there are 5 times(5 shot) local descriptors selected, then sum 5 times similarities for one query local descriptor. If I miss sth, please help me figure it out.

测试集

你好,训练的时候,就用测试集做验证,会不会导致模型提前见到这些数据,一直很苦恼这个问题

Question on paper figure

Hi @WenbinLee ,
Great work. I'm writing a bachelor thesis on improving few-shot learning through data augmentation and it references your paper. Could I ask you to provide the code for plotting the following figures that you made in the paper. It would be very much appreciated!
image

The results are different from the paper on miniImagenet dataset

Sorry to bother you but I have trained the 5-way 1-shot model (Conv-64F) from scratch and found the avearge test accuracy is 46.63±0.80% which is lower than the results provided in the paper.
I didn't modify the code. The dataset and the split csv files I used are provided by RelationNet (https://github.com/floodsung/LearningToCompare_FSL). Is there something wrong in the dataet processing or any other aspects?
Thanks for your attention.
image

Some questions about resnet

Very nice job!!! I tried to use resnet as a backbone just like what you did in my own experiment. However, it didn't improve performance as we expected and even performed worse than 4-conv. I wonder if there are some tricks when you train your model with a resnet. Thank you very much.

Inference on one image only

Does anyone here have a code for doing inference but only for one image? I really appreciate it if you can share the idea and code.

Thanks

A question about k-nearest neighbors

您好!看了您的论文有一个地方不太明白。您在文中说“For each descriptor xi, we find its k-nearest neighbors”。有441个local descriptors,在5way 5shot5的情况下,假设现在计算support set中与query image第n个descriptor最近的k个descriptors,请问是只在support set的5个对应的第n个descriptor找k个最近邻的还是在所有5*441 descriptor上找k个最近邻。另外实验设置,我看您在table1中写的k=3,shot为1的时候k也是3吗?
谢谢您

a question about ablation study

hello,
sorry for asking you here as i did not find the email in your paper. I have a question about an important experiment. Do you compare your network with the baseline that compute cosine distance after global pooling (as is done in prototypical network). That can be seen as to use 1 vector vs 1 vector to compute distance, and meanwhile yours is many vectors vs many vectors.
I think the greatest novelty in your work is to use local features instead of global feature after pooling. However, a baseline model that remains all the parts the same except the global pooling added is missing. Did you have such comparison experiments?

Does this DN4 network contains a pre-triaing stage?

Hello, this is a great work and thank you for open the resource.
I realized that a lot of few-shot learning network has a pre-training stage and maybe fine-tuning during the classification. But I have not found any code regarding to the pre-training, so does the DN4 need a pre-training or it is just train from scratch based on the data with a few labeled samples?

why you used --ravi

When** I Try to run your code i get this error
File Not Found Error: [Errno 2] No such file or directory: '/Datasets/CubBirds--ravi/train.csv'
what is ravi in that? why you used ravi ?
only instead of miniImagenet i used cub-200

(parser.add_argument('--dataset_dir', default='/Datasets/miniImageNet--ravi', help='/miniImageNet'))

CUB

您好,请问对于CUB数据集,epoch和miniImagenet一样还是30吗?因为感觉CUB数据集减少了。学习率衰减仍是10个epoch减一半吗?我对于参数调整不太敏感,希望收到作者的回复

Could you please share your split csv files?

Hi. I'm really interested in your work, and I notice that the "os.listdir(images_dir)" is not sorted,

classes_list = [class_name for class_name in os.listdir(images_dir) if os.path.isdir(os.path.join(images_dir, class_name))]

so there might be some unexpected order here. Could you kindly share your csv files for verification?
Thanks in advance.

Experiment results

Hi,

Thank you very much to share your code with us!

I try to reproduce your results in your paper, and rerun you code directly. But I found the results always a bit lower than that reported in your paper. Should some hyperparameters be tuned?

Also,I found the learning rate decayed 0.05 each interval. Should it be changed to 0.5, or 0.05 is OK?

Hope to hear from you~

About preprocessing on Stanford_Cars

Hi, thanks for your cool work. I have a question about Stanford_Cars.

I download all images of stanford_cars from https://ai.stanford.edu/~jkrause/cars/car_dataset.html.
The download file is as: car_ims/000001.jpg, 000002.jpg, ..., 016185.jpg
It seems that the provided StanforCar_prepare_csv.py does not handle on this file?

Is there any other preprocess on the downloaded car_ims? Thanks!

细粒度数据集准确率

作者您好!上次有关代码报错的issue非常感谢您能及时的回复,我是可以跑通backbone为Conv64F的模型的。
但是本周我在细粒度数据集StanfordDogs上重新跑了一下2019版本的模型,训练完毕以后经过测试发现5way1shot和5way5shot任务的准确率都比论文中的准确率有大幅度提高,但我并没有对代码进行修改,不知道这是什么情况呢?
backbone为Conv64F,论文中的5way1shot和5way5shot的准确率分别为45.41±0.76和63.51±0.62:
image
我对该模型重新进行训练以及测试后,5way1shot和5way5shot的准确率分别为51.44和72.92:
image
image

代码报错

作者您好,我最近在研究小样本图像分类算法,看到您的这篇论文我感到非常值得学习,但是代码下载下来发现有报错,不知道是什么原因?代码如下:

		if self.maml:
			self.C1 = Conv2d_fw(indim, bottleneckdim, kernel_size=1,  bias=False)
			self.BN1 = BatchNorm2d_fw(bottleneckdim)
			self.C2 = Conv2d_fw(bottleneckdim, bottleneckdim, kernel_size=3, stride=2 if half_res else 1,padding=1)
			self.BN2 = BatchNorm2d_fw(bottleneckdim)
			self.C3 = Conv2d_fw(bottleneckdim, outdim, kernel_size=1, bias=False)

以上代码中,Conv2d_fw、BatchNorm2d_fw都出现了报错,没找到这个是在哪里定义的?恳求作者帮忙指点一下,非常感谢!

batch_size只能设为1?

你好,请问这个代码只支持batch_size=1吗?我看了和运行了DN4_Train_5way5shot.py文件,发现把batch_size设为2时,会把2个episode的support set、query set糅合在一起,就是episode1中的support set 的 class 0 和 episode2 中的support set 的class 0的样本会当成是同一个class 0,相当于class 0变成了10 shot,但这10个样本实际来自2个不同的类。

BN parameters followup question

In a previous issue concerning BN parameter freezing after first epoch in the old DN4 version (#12) you mentioned it is done in order to prevent performance degradation which I assume is caused by overfitting to the training set distributions. However, in the new version you don't do it anymore. Curiously enough after removing the BN parameter freezing I even obtained a slight increase in accuracy R@1. Could you explain what is happening? I was always skeptical about the approach in your code to freeze after the 1st epoch, since this means we basically treat the rest of the training as fine-tuning - but this doesn't make sense, since we randomly shuffle the dataset in each epoch and randomly construct the mini-batches, plus we don't use a different split for finetuning. Thank you @WenbinLee

Additional notes:
Before, when freezing the BN parameters after the first epoch, I was using kaiming init:

def init_weights_kaiming(m):
    if isinstance(m, nn.Conv2d) or isinstance(m, nn.Linear):
        nn.init.kaiming_normal_(m.weight, mode='fan_out', nonlinearity='leaky_relu')
        if m.bias is not None:
            nn.init.constant_(m.bias, 0)

When switching to normal init, the performance wouldn't improve after the first epoch (after freezing the BN parameters) and after a 2 epochs it would start degrading. When BN freezing was removed, the training was working well.

About BN parameters

In your code I see that you fix the parameters of Batch Normalization after 1 epoch (10000 episodes), but when I remove the constraint (i.e., before training use model.train(), and before val/test use model.eval()), the performance will drop sharply.

Have you observed the same degradation w/o fixing the BN params? and why is that?

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.