Skip to content

Latest commit

History

70 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Official implementation for SHOT

  • 2022/6/6 We correct a bug in the pseudo-labeling function (def obtain_label), many thanks to @TomSheng21.
  • 2022/2/8 We upload the pretrained source models via Google drive in pretrained-models.md.

Attention-v2: we release the code of our recent black-box UDA method (DINE, https://arxiv.org/pdf/2104.01539.pdf) in the following repository (https://github.com/tim-learn/DINE).

Attention: The code of our stronger TPAMI extension (SHOT++, https://arxiv.org/pdf/2012.07297.pdf) has been released in a new repository (https://github.com/tim-learn/SHOT-plus).

Results:

Note that we update the code and further consider the standard learning rate scheduler like DANN and report new results in the final camera ready version. Please refer results.md for the detailed results on various datasets.

We have updated the results for Digits. Now the results of SHOT-IM for Digits are stable and promising. (Thanks to @wengzejia1 for pointing the bugs in uda_digit.py).

Framework:

Prerequisites:

  • python == 3.6.8
  • pytorch ==1.1.0
  • torchvision == 0.3.0
  • numpy, scipy, sklearn, PIL, argparse, tqdm

Dataset:

  • Please manually download the datasets Office, Office-Home, VisDA-C, Office-Caltech from the official websites, and modify the path of images in each '.txt' under the folder './object/data/'. [**How to generate such txt files could be found in https://github.com/tim-learn/Generate_list **]

  • Concerning the Digits dsatasets, the code will automatically download three digit datasets (i.e., MNIST, USPS, and SVHN) in './digit/data/'.

Training:

  1. Unsupervised Closed-set Domain Adaptation (UDA) on the Digits dataset
    • MNIST -> USPS (m2u) SHOT (cls_par = 0.1) and SHOT-IM (cls_par = 0.0)
    cddigit/pythonuda_digit.py--dsetm2u--gpu_id0--outputckps_digits--cls_par0.0pythonuda_digit.py--dsetm2u--gpu_id0--outputckps_digits--cls_par0.1
  2. Unsupervised Closed-set Domain Adaptation (UDA) on the Office/ Office-Home dataset
    • Train model on the source domain A (s = 0)
    cdobject/pythonimage_source.py--trteval--dauda--outputckps/source/--gpu_id0--dsetoffice--max_epoch100--s0
    • Adaptation to other target domains D and W, respectively
    pythonimage_target.py--cls_par0.3--dauda--output_srcckps/source/--outputckps/target/--gpu_id0--dsetoffice--s0
  3. Unsupervised Closed-set Domain Adaptation (UDA) on the VisDA-C dataset
    • Synthetic-to-real
    cdobject/pythonimage_source.py--trteval--outputckps/source/--dauda--gpu_id0--dsetVISDA-C--netresnet101--lr1e-3--max_epoch10--s0pythonimage_target.py--cls_par0.3--dauda--dsetVISDA-C--gpu_id0--s0--output_srcckps/source/--outputckps/target/--netresnet101--lr1e-3
  4. Unsupervised Partial-set Domain Adaptation (PDA) on the Office-Home dataset
    • Train model on the source domain A (s = 0)
    cdobject/pythonimage_source.py--trteval--dapda--outputckps/source/--gpu_id0--dsetoffice-home--max_epoch50--s0
    • Adaptation to other target domains C and P and R, respectively
    pythonimage_target.py--cls_par0.3--threshold10--dapda--dsetoffice-home--gpu_id0--s0--output_srcckps/source/--outputckps/target/
  5. Unsupervised Open-set Domain Adaptation (ODA) on the Office-Home dataset
    • Train model on the source domain A (s = 0)
    cdobject/pythonimage_source.py--trteval--daoda--outputckps/source/--gpu_id0--dsetoffice-home--max_epoch50--s0
    • Adaptation to other target domains C and P and R, respectively
    pythonimage_target_oda.py--cls_par0.3--daoda--dsetoffice-home--gpu_id0--s0--output_srcckps/source/--outputckps/target/
  6. Unsupervised Multi-source Domain Adaptation (MSDA) on the Office-Caltech dataset
    • Train model on the source domains A (s = 0), C (s = 1), D (s = 2), respectively
    cdobject/pythonimage_source.py--trteval--dauda--outputckps/source/--gpu_id0--dsetoffice-caltech--max_epoch100--s0pythonimage_source.py--trteval--dauda--outputckps/source/--gpu_id0--dsetoffice-caltech--max_epoch100--s1pythonimage_source.py--trteval--dauda--outputckps/source/--gpu_id0--dsetoffice-caltech--max_epoch100--s2
    • Adaptation to the target domain W (t = 3)
    pythonimage_target.py--cls_par0.3--dauda--output_srcckps/source/--outputckps/target/--gpu_id0--dsetoffice--s0pythonimage_target.py--cls_par0.3--dauda--output_srcckps/source/--outputckps/target/--gpu_id0--dsetoffice--s1pythonimage_target.py--cls_par0.3--dauda--output_srcckps/source/--outputckps/target/--gpu_id0--dsetoffice--s2pythonimage_multisource.py--cls_par0.0--dauda--dsetoffice-caltech--gpu_id0--t3--output_srcckps/source/--outputckps/target/
  7. Unsupervised Multi-target Domain Adaptation (MTDA) on the Office-Caltech dataset
    • Train model on the source domain A (s = 0)
    cdobject/pythonimage_source.py--trteval--dauda--outputckps/source/--gpu_id0--dsetoffice-caltech--max_epoch100--s0
    • Adaptation to multiple target domains C and P and R at the same time
    pythonimage_multitarget.py--cls_par0.3--dauda--dsetoffice-caltech--gpu_id0--s0--output_srcckps/source/--outputckps/target/
  8. Unsupervised Partial Domain Adaptation (PDA) on the ImageNet-Caltech dataset without source training by ourselves (using the downloaded Pytorch ResNet50 model directly)
    • ImageNet -> Caltech (84 classes) [following the protocol in PADA]
    cdobject/pythonimage_pretrained.py--gpu_id0--outputckps/target/--cls_par0.3

Please refer ./object/run.sh for all the settings for different methods and scenarios.

Citation

If you find this code useful for your research, please cite our papers

@inproceedings{liang2020we, title={Do We Really Need to Access the Source Data? Source Hypothesis Transfer for Unsupervised Domain Adaptation}, author={Liang, Jian and Hu, Dapeng and Feng, Jiashi}, booktitle={International Conference on Machine Learning (ICML)}, pages={6028--6039},
year={2020}
}
@article{liang2021source, title={Source Data-absent Unsupervised Domain Adaptation through Hypothesis Transfer and Labeling Transfer}, author={Liang, Jian and Hu, Dapeng and Wang, Yunbo and He, Ran and Feng, Jiashi}, journal={IEEE Transactions on Pattern Analysis and Machine Intelligence (TPAMI)},
year={2021}, note={In Press} }

Contact

About

code released for our ICML 2020 paper "Do We Really Need to Access the Source Data? Source Hypothesis Transfer for Unsupervised Domain Adaptation"

Topics

Resources

Stars

497 stars

Watchers

5 watching

Forks

Releases

Packages

Used by

Contributors

Languages