{"id":20806526,"url":"https://github.com/yfzhang114/adanpc","last_synced_at":"2025-05-07T04:25:43.853Z","repository":{"id":160912279,"uuid":"632709647","full_name":"yfzhang114/AdaNPC","owner":"yfzhang114","description":"This is an official PyTorch implementation of the ICML 2023 paper AdaNPC and SIGKDD paper DRM.","archived":false,"fork":false,"pushed_at":"2024-04-16T08:31:54.000Z","size":474,"stargazers_count":85,"open_issues_count":7,"forks_count":7,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-31T06:24:23.796Z","etag":null,"topics":["domain-generalization","machine-learning","robustness","test-time-adaptation"],"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/yfzhang114.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2023-04-26T01:12:07.000Z","updated_at":"2025-02-10T01:55:59.000Z","dependencies_parsed_at":null,"dependency_job_id":"47cc88a5-df18-4148-8049-2a4313a12ae0","html_url":"https://github.com/yfzhang114/AdaNPC","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/yfzhang114%2FAdaNPC","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yfzhang114%2FAdaNPC/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yfzhang114%2FAdaNPC/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yfzhang114%2FAdaNPC/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yfzhang114","download_url":"https://codeload.github.com/yfzhang114/AdaNPC/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252812007,"owners_count":21808061,"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-generalization","machine-learning","robustness","test-time-adaptation"],"created_at":"2024-11-17T19:21:04.086Z","updated_at":"2025-05-07T04:25:43.810Z","avatar_url":"https://github.com/yfzhang114.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AdaNPC: Exploring Non-Parametric Classifier for Test-Time Adaptation\n\nThis codebase is the official implementation of [`AdaNPC: Exploring Non-Parametric Classifier for Test-Time Adaptation`](https://arxiv.org/abs/2304.12566) (**ICML, 2023**), and  [`Domain-Specific Risk Minimization for Out-of-Distribution Generalization\n`](https://arxiv.org/abs/2208.08661) (**SIGKDD, 2023**)\n\nThis codebase is mainly based on [DomainBed](https://github.com/facebookresearch/DomainBed), and [T3A](https://github.com/matsuolab/T3A).\n\n## Installation\n\n\n## Quick start\n#### (1) Downlload the datasets\n\n```sh\npython download.py --data_dir=/my/datasets/path \n```\nNote: set the target datasets in the download.py\n\n\n#### (2) Train a model on source domains\n```sh\npython -m domainbed.scripts.train\\\n       --data_dir /my/datasets/path\\\n       --output_dir /my/pretrain/path\\\n       --algorithm ERM\\\n       --dataset PACS\\\n       --hparams \"{\\\"backbone\\\": \\\"resnet50\\\"}\" \n```\nThis scripts will produce new directory `/my/pretrain/path`, which include the full training log. \n\nNote: change `--dataset PACS` for training on other datasets (e.g., `VLCS`, `OfficeHome`, `TerraIncognita`). \n\nNote: change `--hparams \"{\\\"backbone\\\": \\\"resnet50\\\"}\"` for using other backbones (e.g., `resnet18`, `ViT-B16`, `HViT`). \n\n\n#### (3) Evaluate model with test time adaptation\n```sh\npython -m domainbed.scripts.unsupervised_adaptation\\\n       --input_dir=/my/pretrain/path\\\n       --adapt_algorithm=T3A\n```\nThis scripts will produce a new file in `/my/pretrain/path`, whose name is `results_{adapt_algorithm}.jsonl`. \n\nNote: change `--adapt_algorithm=T3A` for using other test time adaptation methods (`AdaNPC`, `AdaNPCBN`, or `TentClf`). \n\n\n\n#### (4) Evaluate model with fine-tuning classifier\n```sh\npython -m domainbed.scripts.supervised_adaptation\\\n       --input_dir=/my/pretrain/path\\\n       --ft_mode=clf\n```\nThis scripts will produce a new file in `/my/pretrain/path`, whose name is `results_{ft_mode}.jsonl`. \n\n\n## Available backbones\n\n* resnet18\n* resnet50\n* BiT-M-R50x3\n* BiT-M-R101x3\n* BiT-M-R152x2\n* ViT-B16\n* ViT-L16\n* DeiT\n* Hybrid ViT (HViT)\n* MLP-Mixer (Mixer-L16)\n\n## Reproducing results for AdaNPC\n#### Table 1 and Figure 2 (Tuned ERM and CORAL)\n\nYou can use `scripts/hparam_search.sh`. Specifically, for each dataset and base algorithm, you can just type a following command.\n```\nsh scripts/hparam_search.sh resnet50 PACS ERM\n```\nNote that, it automatically starts 240 jobs, and take many times to finish. \n\n\n#### Table 2 and Figure 1 (ERM with various backbone)\n\nYou can use `scripts/launch.sh`. Specifically, for each backbone, you can just type following commands. \n\nSpecifically, for baselines based on ResNet-50 (PLClf, PLFull, SHOT, SHOTIM, T3A)\n\n```\nsh scripts/launch.sh pretrain resnet50 10 3 local ERM\nsh scripts/launch.sh sup resnet50 10 3 local ERM\nsh scripts/launch.sh unsup resnet50 10 3 local ERM\n```\n\nfor baselines based on ResNet-50-BN (TentClf, TentNorm, TentFull)\n\n```\nsh scripts/launch.sh pretrain resnet50-BN 10 3 local ERM\nsh scripts/launch.sh sup resnet50-BN 10 3 local ERM\nsh scripts/launch.sh unsup resnet50-BN 10 3 local ERM\n```\n\nfor baselines based on KNN training algorithm\n\n```\nsh scripts/launch.sh pretrain resnet50 10 3 local KNN\nsh scripts/launch.sh sup resnet50 10 3 local AdaNPC\nsh scripts/launch.sh unsup resnet50 10 3 local AdaNPC\n```\n\n## Reproducing results for DRM\n\n```\nsh scripts/launch.sh pretrain resnet50 10 3 local DRM\nsh scripts/launch.sh sup resnet50 10 3 local DRM\nsh scripts/launch.sh unsup resnet50 10 3 local DRM\n```\n\n## License\n\nThis source code is released under the MIT license, included [here](LICENSE).\n\n### Citation \nIf you find this repo useful, please consider citing: \n```\n@inproceedings{zhang2023adanpc,\n  title={Adanpc: Exploring non-parametric classifier for test-time adaptation},\n  author={Zhang, Yifan and Wang, Xue and Jin, Kexin and Yuan, Kun and Zhang, Zhang and Wang, Liang and Jin, Rong and Tan, Tieniu},\n  booktitle={International Conference on Machine Learning},\n  pages={41647--41676},\n  year={2023},\n  organization={PMLR}\n}\n\n\n@misc{zhang2022domainspecific,\n      title={Domain-Specific Risk Minimization for Out-of-Distribution Generalization}, \n      author={Yi-Fan Zhang and Jindong Wang and Jian Liang and Zhang Zhang and Baosheng Yu and Liang Wang and Dacheng Tao and Xing Xie},\n      year={2023},\n      archivePrefix={KDD '23: Proceedings of the 29th ACM SIGKDD Conference on Knowledge Discovery and Data Mining},\n      primaryClass={cs.LG}\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyfzhang114%2Fadanpc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyfzhang114%2Fadanpc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyfzhang114%2Fadanpc/lists"}