{"about":{"site":"https://codewithpapers.app","non_affiliation":"Code with Papers and Syntology are not affiliated with, endorsed by, or sponsored by Papers with Code, Meta, or the pwc-archive mirror.","licence":"CC BY-SA 4.0","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","attribution":"https://codewithpapers.app/attribution","modified":"archive material modified by Syntology; see the attribution page"},"url":"/paper/domain-generalization-needs-stochastic-weight","title":"SWAD: Domain Generalization by Seeking Flat Minima","arxiv_id":"2102.08604","date":"2021-02-17","proceeding":"NeurIPS 2021 12","authors":["Junbum Cha","Sanghyuk Chun","Kyungjae Lee","Han-Cheol Cho","Seunghyun Park","Yunsung Lee","Sungrae Park"],"abstract":"Domain generalization (DG) methods aim to achieve generalizability to an unseen target domain by using only training data from the source domains. Although a variety of DG methods have been proposed, a recent study shows that under a fair evaluation protocol, called DomainBed, the simple empirical risk minimization (ERM) approach works comparable to or even outperforms previous methods. Unfortunately, simply solving ERM on a complex, non-convex loss function can easily lead to sub-optimal generalizability by seeking sharp minima. In this paper, we theoretically show that finding flat minima results in a smaller domain generalization gap. We also propose a simple yet effective method, named Stochastic Weight Averaging Densely (SWAD), to find flat minima. SWAD finds flatter minima and suffers less from overfitting than does the vanilla SWA by a dense and overfit-aware stochastic weight sampling strategy. SWAD shows state-of-the-art performances on five DG benchmarks, namely PACS, VLCS, OfficeHome, TerraIncognita, and DomainNet, with consistent and large margins of +1.6% averagely on out-of-domain accuracy. We also compare SWAD with conventional generalization methods, such as data augmentation and consistency regularization methods, to verify that the remarkable performance improvements are originated from by seeking flat minima, not from better in-domain generalizability. Last but not least, SWAD is readily adaptable to existing DG methods without modification; the combination of SWAD and an existing DG method further improves DG performances. Source code is available at https://github.com/khanrc/swad.","url_abs":"https://arxiv.org/abs/2102.08604v4","url_pdf":"https://arxiv.org/pdf/2102.08604v4.pdf","source":{"archive":"pwc-archive (Hugging Face), CC BY-SA 4.0","snapshot":"2025-07-28","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","row_kind":"abstracts"},"code_links":[{"paper_slug":"domain-generalization-needs-stochastic-weight","repo_url":"https://github.com/khanrc/swad","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":1,"framework":"pytorch","reach":null},{"paper_slug":"domain-generalization-needs-stochastic-weight","repo_url":"https://github.com/kakaobrain/miro","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok","spdx":"MIT"}},{"paper_slug":"domain-generalization-needs-stochastic-weight","repo_url":"https://github.com/salesforce/ensemble-of-averages","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"pytorch","reach":null},{"paper_slug":"domain-generalization-needs-stochastic-weight","repo_url":"https://github.com/ys-zong/medfair","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":0,"framework":"pytorch","reach":{"status":"ok"}}],"tasks":[{"task_slug":"domain-generalization","task_name":"Domain Generalization"},{"task_slug":"generalization-bounds","task_name":"Generalization Bounds"},{"task_slug":"robust-classification","task_name":"Robust classification"}],"methods":[{"method_slug":"stochastic-weight-averaging","method_name":"Stochastic Weight Averaging"}],"datasets_introduced":[],"methods_introduced":[],"results":[{"leaderboard":"/sota/domain-generalization-on-domainnet","task":"Domain Generalization","dataset":"DomainNet","model":"SWAD (ResNet-50)","rank_in_archive_order":30,"of":38,"metrics":{"Average Accuracy":"46.5"},"uses_additional_data":false},{"leaderboard":"/sota/domain-generalization-on-office-home","task":"Domain Generalization","dataset":"Office-Home","model":"SWAD (ResNet-50)","rank_in_archive_order":30,"of":45,"metrics":{"Average Accuracy":"70.6"},"uses_additional_data":false},{"leaderboard":"/sota/domain-generalization-on-pacs-2","task":"Domain Generalization","dataset":"PACS","model":"SWAD (ResNet-50)","rank_in_archive_order":31,"of":133,"metrics":{"Average Accuracy":"88.1"},"uses_additional_data":false},{"leaderboard":"/sota/domain-generalization-on-terraincognita","task":"Domain Generalization","dataset":"TerraIncognita","model":"SWAD (ResNet-50)","rank_in_archive_order":25,"of":30,"metrics":{"Average Accuracy":"50.0"},"uses_additional_data":false},{"leaderboard":"/sota/domain-generalization-on-vlcs","task":"Domain Generalization","dataset":"VLCS","model":"SWAD (ResNet-50)","rank_in_archive_order":29,"of":37,"metrics":{"Average Accuracy":"79.1"},"uses_additional_data":false}],"syntology":{"atlas_url":"https://app.syntology.ai/?focus=2102.08604","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2102.08604"}},"developers":"https://syntology.ai/developers","read_at":"2026-09-24T18:15:14+00:00","read_at_is":"when the build read Syntology's graph, not when any sample ran","claim":"Per-sample execution status on synthesized fixtures; not a correctness claim about the paper. Samples come from repositories linked to the paper, official or community; repo_kind says which.","repos":[{"provenance":"deterministic:regex_extraction","url":"https://github.com/khanrc/swad","reach":null},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/ys-zong/medfair","reach":{"status":"ok"}},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/salesforce/ensemble-of-averages","reach":null},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/kakaobrain/miro","reach":{"status":"ok","spdx":"MIT"}}],"summary":{"ran":2,"unverified":1},"by_repo_kind":{"official":{"samples":3,"ran":2,"repositories":1}},"repo_kind_vocabulary":{"official":"The archive marks this repository official for the paper","named_in_paper":"The archive records that the paper mentions this repository; it is not marked official","listed":"In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper","found_in_text":"Syntology found this repository in the paper's own text; whether it is the authors' implementation is not asserted","community":"Not in the archive's code links for this paper; a community repository Syntology harvested"},"n_pointer_only_for_licence":0,"samples":[{"code_sha256_prefix":"99a7b5a0b73a9f77","entry":"AveragedModel","repo":"khanrc/swad","repo_kind":"official","path":"domainbed/swad.py","file_url":"https://github.com/khanrc/swad/blob/HEAD/domainbed/swad.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":"deterministic","behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"99a7b5a0b73a9f77"}},{"code_sha256_prefix":"fe60019a6b11c07e","entry":"LossValley","repo":"khanrc/swad","repo_kind":"official","path":"domainbed/swad.py","file_url":"https://github.com/khanrc/swad/blob/HEAD/domainbed/swad.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"fe60019a6b11c07e"}},{"code_sha256_prefix":"89e9d638917966b7","entry":"SWADBase","repo":"khanrc/swad","repo_kind":"official","path":"domainbed/swad.py","file_url":"https://github.com/khanrc/swad/blob/HEAD/domainbed/swad.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"89e9d638917966b7"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}