GithubHelp home page GithubHelp logo

albert0147 / aad_sfda Goto Github PK

View Code? Open in Web Editor NEW
55.0 3.0 6.0 588 KB

Code for our NeurIPS 2022 (spotlight) paper 'Attracting and Dispersing: A Simple Approach for Source-free Domain Adaptation'

Python 95.84% Shell 1.54% Jupyter Notebook 2.63%
source-free-domain-adaptation neurips2022 neurips-2022

aad_sfda's Introduction

(NeurIPS 2022 Spotlight) Attracting and Dispersing: A Simple Approach for Source-free Domain Adaptation

Shiqi Yang, Yaxing Wang, Kai Wang, Shangling Jui and Joost van de Weijer

Code for our paper 'Attracting and Dispersing: A Simple Approach for Source-free Domain Adaptation'

[project][arxiv]

Contributions

  • We provide a surprisingly simple solution for source-free domain adaptation, which is an upperbound of the proposed clustering objective:

img

  • And we can relate several methods in domain adaptation, source-free domain adaptation and contrastive learning via the perspective of discriminability and diversity:

img2

code on VisDA

We use pytoch 1.3 with cuda 10.0

Attention: Please note that the kl_div in pytorch equals to dot product if there is no log for the input.

Download VisDA dataset and change the path in the code to it. First train model on Source domain, directly run src_pretrain.py Source-free domain adaptation, directly run tar_adaptation.py

You can insert the core part (loss computing starting in Line 297 in tar_adaptation.py) into code of any other SFDA method, such as our NRC (NeurIPS 2021) or SHOT (ICML 2020)

For computing SND, you can use the file snd.py (code is from SND), in the paper we compute SND after only training for a few epochs (~5 on visda).

aad_sfda's People

Contributors

albert0147 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

Watchers

 avatar  avatar  avatar

aad_sfda's Issues

A question about implementation details

Dear author,

I'm an undergraduate student who is quite interested in SFDA, and I have been following your work from G-SFDA, NRC to AaD. I really appreciate your works and the wonderful performance they achieve.

Recently, I'm trying to understand your work of AaD. However, I become a little confused about some implementation details as I conbine your paper and source code.

From my understanding, the B_i in div term contains all other items in a mini batch except those in C_i. In other words, items that are k nearest neighbors should be excluded from B_i, as presented in the paper. However, in your code I copied below:

mask = torch.ones((inputs_target.shape[0], inputs_target.shape[0]))
diag_num = torch.diag(mask)
mask_diag = torch.diag_embed(diag_num)
mask = mask - mask_diag
if args.noGRAD:
    copy = softmax_out.T.detach().clone()
else:
    copy = softmax_out.T  # .detach().clone()  #
dot_neg = softmax_out @ copy  # batch x batch
dot_neg = (dot_neg * mask.cuda()).sum(-1)  # batch
neg_pred = torch.mean(dot_neg)
loss += neg_pred * alpha

it seems that only diagonal entries in mask are set to 0, rather than k nearest neighbors.

I suppose I must have some misunderstandings, so I create the issue, hoping to get your answer. I would appreciate it if you could answer my qusetion. Looking forward to your reply.

Experimental setting for Source-free paritial-set DA

Hi, professor. I'm very interesting in your paper. Could you provide the Office-Home experiment setting file in paritial-set DA settings, i.e., hyper-parameters K and β. Thank you very much and look forward to your early reply.

Selecting beta with SND

Hi, I really appreciate you sharing your code here. I have a question for you. Where in your code does it reflect that the value of beta is automatically selected using the SND method? Thank you!

It seems the code of loss part does not match the paper

Hi Shiqi,

Thanks you very much for providing code and congratulations on your paper acceptance!

After reading the loss function part, I could not find how the code reflects Eq.5 of paper. Please correct me if I miss anything:

First, the first term of Eq.5 is consistency between local neighbours. I understand you use a memory bank to save softmax outputs, and then get K neighbours.

softmax_out_un = softmax_out.unsqueeze(1).expand(-1, args.K,

However, I cannot find the connection between KlD loss and the first term in Eq.5

(F.kl_div(softmax_out_un, score_near, reduction='none').sum(-1)).sum(1))

This line of code does not equal to the first term of Eq.5. I am confused by this, please help me solve this.

Second, for the second term, it is to disperse the prediction of potential dissimilar features. However, your code does not reflect this thing.

dot_neg = (dot_neg * mask.cuda()).sum(-1) #batch

Given a test sample, this line of code regards the rest of samples in the batch as background. This is also not equal to the definition of background set in the paper.

This work claims that "provide a surprisingly simple solution for source-free domain adaptation, which is an upperbound of the proposed clustering objective". Therefore, I expect the code corresponds to equation.

Please help me address the concern, and correct my if I misunderstand anything.

Low accuracy of OfficeHome dataset

Thanks to the author for contributing the code!
Based on the hyperparameters provided in the paper, I found in my experiments that the accuracy of the OfficeHome dataset is very low (only 1.58% in task A->P) and seems difficult to fit.

The source domain model parameters I used were provided by SHOT.

A question about dataloader for test

Hi, there!

I notice that in the dataloader for test, the parameter shuffle of the init of DataLoader is set to False in Visda17, whereas in office-home and office31, it is set to True. Is this setting on purpose?

i.e. in line 120 of tar_adaptation.py, line 154 of office-home/train_tar.py, line 197 of office-home/office31_tar.py

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.