{"id":13737580,"url":"https://github.com/tim-learn/SHOT","last_synced_at":"2025-05-08T14:33:04.936Z","repository":{"id":44446780,"uuid":"272206582","full_name":"tim-learn/SHOT","owner":"tim-learn","description":"code released for our ICML 2020 paper \"Do We Really Need to Access the Source Data? Source Hypothesis Transfer for Unsupervised Domain Adaptation\"","archived":false,"fork":false,"pushed_at":"2024-02-22T08:44:47.000Z","size":515,"stargazers_count":436,"open_issues_count":4,"forks_count":78,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-11-15T06:32:05.911Z","etag":null,"topics":["domain-adaptation","icml-2020","multi-source-domain-adaptation","partial-set-domain-adaptation","pseudo-labeling","source-free-domain-adaptation","source-hypothesis-transfer","transfer-learning"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tim-learn.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-06-14T13:21:36.000Z","updated_at":"2024-11-13T08:54:07.000Z","dependencies_parsed_at":"2023-01-19T18:20:28.556Z","dependency_job_id":"547a7b21-6147-4d17-8c7c-a0e4b267732e","html_url":"https://github.com/tim-learn/SHOT","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tim-learn%2FSHOT","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tim-learn%2FSHOT/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tim-learn%2FSHOT/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tim-learn%2FSHOT/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tim-learn","download_url":"https://codeload.github.com/tim-learn/SHOT/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253085771,"owners_count":21851697,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["domain-adaptation","icml-2020","multi-source-domain-adaptation","partial-set-domain-adaptation","pseudo-labeling","source-free-domain-adaptation","source-hypothesis-transfer","transfer-learning"],"created_at":"2024-08-03T03:01:53.980Z","updated_at":"2025-05-08T14:33:04.503Z","avatar_url":"https://github.com/tim-learn.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# Official implementation for **SHOT**\r\n\r\n## [**[ICML-2020] Do We Really Need to Access the Source Data? Source Hypothesis Transfer for Unsupervised Domain Adaptation**](http://proceedings.mlr.press/v119/liang20a.html)\r\n\r\n\r\n\r\n- **2022/6/6      We correct a bug in the pseudo-labeling function (def obtain_label), many thanks to @TomSheng21.**\r\n- **2022/2/8      We upload the pretrained source models via Google drive in [pretrained-models.md](./pretrained-models.md).**\r\n\r\n\r\n\r\n### 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).*** \r\n\r\n#### 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).*** \r\n\r\n\r\n\r\n### Results:\r\n\r\n#### **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](./results.md) for the detailed results on various datasets.\r\n\r\n*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**).*\r\n\r\n\r\n### Framework:  \r\n\r\n\u003cimg src=\"figs/shot.jpg\" width=\"600\"/\u003e\r\n\r\n### Prerequisites:\r\n- python == 3.6.8\r\n- pytorch ==1.1.0\r\n- torchvision == 0.3.0\r\n- numpy, scipy, sklearn, PIL, argparse, tqdm\r\n\r\n### Dataset:\r\n\r\n- Please manually download the datasets [Office](https://drive.google.com/file/d/0B4IapRTv9pJ1WGZVd1VDMmhwdlE/view), [Office-Home](https://drive.google.com/file/d/0B81rNlvomiwed0V1YUxQdC1uOTg/view), [VisDA-C](https://github.com/VisionLearningGroup/taskcv-2017-public/tree/master/classification), [Office-Caltech](http://www.vision.caltech.edu/Image_Datasets/Caltech256/256_ObjectCategories.tar) 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 **]\r\n\r\n- Concerning the **Digits** dsatasets, the code will automatically download three digit datasets (i.e., MNIST, USPS, and SVHN) in './digit/data/'.\r\n\r\n\r\n### Training:\r\n1. ##### Unsupervised Closed-set Domain Adaptation (UDA) on the Digits dataset\r\n\t- MNIST -\u003e USPS (**m2u**)   SHOT (**cls_par = 0.1**) and SHOT-IM (**cls_par = 0.0**)\r\n\t```python\r\n\t cd digit/\r\n\t python uda_digit.py --dset m2u --gpu_id 0 --output ckps_digits --cls_par 0.0\r\n\t python uda_digit.py --dset m2u --gpu_id 0 --output ckps_digits --cls_par 0.1\r\n\t```\r\n\t\r\n2. ##### Unsupervised Closed-set Domain Adaptation (UDA) on the Office/ Office-Home dataset\r\n\t- Train model on the source domain **A** (**s = 0**)\r\n    ```python\r\n    cd object/\r\n    python image_source.py --trte val --da uda --output ckps/source/ --gpu_id 0 --dset office --max_epoch 100 --s 0\r\n    ```\r\n\t\r\n\t- Adaptation to other target domains **D and W**, respectively\r\n    ```python\r\n    python image_target.py --cls_par 0.3 --da uda --output_src ckps/source/ --output ckps/target/ --gpu_id 0 --dset office --s 0  \r\n    ```\r\n   \r\n3. ##### Unsupervised Closed-set Domain Adaptation (UDA) on the VisDA-C dataset\r\n\t- Synthetic-to-real \r\n    ```python\r\n    cd object/\r\n\t python image_source.py --trte val --output ckps/source/ --da uda --gpu_id 0 --dset VISDA-C --net resnet101 --lr 1e-3 --max_epoch 10 --s 0\r\n\t python image_target.py --cls_par 0.3 --da uda --dset VISDA-C --gpu_id 0 --s 0 --output_src ckps/source/ --output ckps/target/ --net resnet101 --lr 1e-3\r\n\t ```\r\n\t\r\n4. ##### Unsupervised Partial-set Domain Adaptation (PDA) on the Office-Home dataset\r\n\t- Train model on the source domain **A** (**s = 0**)\r\n\t```python\r\n\t cd object/\r\n\t python image_source.py --trte val --da pda --output ckps/source/ --gpu_id 0 --dset office-home --max_epoch 50 --s 0\r\n\t```\r\n\r\n\t- Adaptation to other target domains **C and P and R**, respectively\r\n\t```python\r\n\t python image_target.py --cls_par 0.3 --threshold 10 --da pda --dset office-home --gpu_id 0 --s 0 --output_src ckps/source/ --output ckps/target/\r\n\t```\r\n   \r\n5. ##### Unsupervised Open-set Domain Adaptation (ODA) on the Office-Home dataset\r\n\t- Train model on the source domain **A** (**s = 0**)\r\n\t```python\r\n\t cd object/\r\n\t python image_source.py --trte val --da oda --output ckps/source/ --gpu_id 0 --dset office-home --max_epoch 50 --s 0\r\n\t```\r\n\t\r\n\t- Adaptation to other target domains **C and P and R**, respectively\r\n\t```python\r\n\t python image_target_oda.py --cls_par 0.3 --da oda --dset office-home --gpu_id 0 --s 0 --output_src ckps/source/ --output ckps/target/\r\n\t```\r\n\t\r\n6. ##### Unsupervised Multi-source Domain Adaptation (MSDA) on the Office-Caltech dataset\r\n\t- Train model on the source domains **A** (**s = 0**), **C** (**s = 1**), **D** (**s = 2**), respectively\r\n\t```python\r\n\t cd object/\r\n\t python image_source.py --trte val --da uda --output ckps/source/ --gpu_id 0 --dset office-caltech --max_epoch 100 --s 0\r\n\t python image_source.py --trte val --da uda --output ckps/source/ --gpu_id 0 --dset office-caltech --max_epoch 100 --s 1\r\n\t python image_source.py --trte val --da uda --output ckps/source/ --gpu_id 0 --dset office-caltech --max_epoch 100 --s 2\r\n\t```\r\n\t\r\n\t- Adaptation to the target domain **W** (**t = 3**)\r\n\t```python\r\n\t python image_target.py --cls_par 0.3 --da uda --output_src ckps/source/ --output ckps/target/ --gpu_id 0 --dset office --s 0\r\n\t python image_target.py --cls_par 0.3 --da uda --output_src ckps/source/ --output ckps/target/ --gpu_id 0 --dset office --s 1\r\n\t python image_target.py --cls_par 0.3 --da uda --output_src ckps/source/ --output ckps/target/ --gpu_id 0 --dset office --s 2\r\n\t python image_multisource.py --cls_par 0.0 --da uda --dset office-caltech --gpu_id 0 --t 3 --output_src ckps/source/ --output ckps/target/\r\n\t```\r\n\t\r\n7. ##### Unsupervised Multi-target Domain Adaptation (MTDA) on the Office-Caltech dataset\r\n\t- Train model on the source domain **A** (**s = 0**)\r\n\t```python\r\n\t cd object/\r\n\t python image_source.py --trte val --da uda --output ckps/source/ --gpu_id 0 --dset office-caltech --max_epoch 100 --s 0\r\n\t```\r\n\t\r\n\t- Adaptation to multiple target domains **C and P and R** at the same time\r\n\t```python\r\n\t python image_multitarget.py --cls_par 0.3 --da uda --dset office-caltech --gpu_id 0 --s 0 --output_src ckps/source/ --output ckps/target/\r\n\t```\r\n\t\r\n8. ##### Unsupervised Partial Domain Adaptation (PDA) on the ImageNet-Caltech dataset without source training by ourselves (using the downloaded Pytorch ResNet50 model directly)\r\n\t- ImageNet -\u003e Caltech (84 classes) [following the protocol in [PADA](https://github.com/thuml/PADA/tree/master/pytorch/data/imagenet-caltech)]\r\n\t```python\r\n\t cd object/\r\n\t python image_pretrained.py --gpu_id 0 --output ckps/target/ --cls_par 0.3\r\n\t```\r\n\r\n**Please refer *./object/run.sh*** for all the settings for different methods and scenarios.\r\n\r\n### Citation\r\n\r\nIf you find this code useful for your research, please cite our papers\r\n\r\n```\r\n@inproceedings{liang2020we, \r\n title={Do We Really Need to Access the Source Data? Source Hypothesis Transfer for Unsupervised Domain Adaptation}, \r\n author={Liang, Jian and Hu, Dapeng and Feng, Jiashi}, \r\n booktitle={International Conference on Machine Learning (ICML)},  \r\n pages={6028--6039},\r\n year={2020}\r\n}\r\n\r\n@article{liang2021source,  \r\n title={Source Data-absent Unsupervised Domain Adaptation through Hypothesis Transfer and Labeling Transfer}, \r\n author={Liang, Jian and Hu, Dapeng and Wang, Yunbo and He, Ran and Feng, Jiashi},   \r\n journal={IEEE Transactions on Pattern Analysis and Machine Intelligence (TPAMI)},\r\n year={2021}, \r\n note={In Press}  \r\n}\r\n```\r\n\r\n\r\n### Contact\r\n\r\n- [liangjian92@gmail.com](mailto:liangjian92@gmail.com)\r\n- [dapeng.hu@u.nus.edu](mailto:dapeng.hu@u.nus.edu)\r\n- [elefjia@nus.edu.sg](mailto:elefjia@nus.edu.sg)\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftim-learn%2FSHOT","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftim-learn%2FSHOT","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftim-learn%2FSHOT/lists"}