{"id":13576061,"url":"https://github.com/Westlake-AI/SEMA","last_synced_at":"2025-04-05T05:30:44.319Z","repository":{"id":222774847,"uuid":"708217008","full_name":"Westlake-AI/SEMA","owner":"Westlake-AI","description":"Switch EMA: A Free Lunch for Better Flatness and Sharpness","archived":false,"fork":false,"pushed_at":"2024-02-16T05:57:49.000Z","size":2293,"stargazers_count":24,"open_issues_count":3,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-11-05T12:32:57.572Z","etag":null,"topics":["image-classification","image-generation","object-detection","optimization","pytorch","regression","regularization","self-supervised-learning","video-prediction"],"latest_commit_sha":null,"homepage":"https://arxiv.org/abs/2402.09240","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Westlake-AI.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":"2023-10-21T21:54:40.000Z","updated_at":"2024-10-29T05:39:17.000Z","dependencies_parsed_at":null,"dependency_job_id":"374b4fce-e8ff-4637-a493-cf59264e4db3","html_url":"https://github.com/Westlake-AI/SEMA","commit_stats":null,"previous_names":["westlake-ai/sema"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Westlake-AI%2FSEMA","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Westlake-AI%2FSEMA/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Westlake-AI%2FSEMA/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Westlake-AI%2FSEMA/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Westlake-AI","download_url":"https://codeload.github.com/Westlake-AI/SEMA/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247294068,"owners_count":20915330,"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":["image-classification","image-generation","object-detection","optimization","pytorch","regression","regularization","self-supervised-learning","video-prediction"],"created_at":"2024-08-01T15:01:06.673Z","updated_at":"2025-04-05T05:30:39.303Z","avatar_url":"https://github.com/Westlake-AI.png","language":"Python","readme":"\u003cdiv align=\"center\"\u003e\n\u003ch2\u003e\u003ca href=\"https://arxiv.org/abs/2402.09240\"\u003eSwitch EMA: A Free Lunch for Better Flatness and Sharpness\u003c/a\u003e\u003c/h2\u003e\n\n[Siyuan Li](https://lupin1998.github.io/)\u003csup\u003e\\*,1,2,3\u003c/sup\u003e, [Zicheng Liu](https://pone7.github.io/)\u003csup\u003e\\*,1,3\u003c/sup\u003e, [Juanxi Tian](https://openreview.net/profile?id=~Juanxi_Tian1)\u003csup\u003e\\*,1\u003c/sup\u003e, [Ge Wang](https://openreview.net/profile?id=~Ge_Wang3)\u003csup\u003e\\*,1,3\u003c/sup\u003e, [Zedong Wang](https://zedongwang.netlify.app/)\u003csup\u003e1\u003c/sup\u003e, [Weiyang Jin](https://openreview.net/profile?id=~Weiyang_Jin1)\u003csup\u003e1\u003c/sup\u003e, [Di Wu](https://scholar.google.com/citations?user=egz8bGQAAAAJ\u0026hl=zh-CN)\u003csup\u003e1,3\u003c/sup\u003e, [Tao Lin](https://scholar.google.co.id/citations?hl=zh-CN\u0026user=QE9pa_cAAAAJ)\u003csup\u003e1\u003c/sup\u003e, [Chen Tan](https://chengtan9907.github.io/)\u003csup\u003e1,3\u003c/sup\u003e, [Yang Liu](https://scholar.google.co.id/citations?user=t1emSE0AAAAJ\u0026hl=zh-CN)\u003csup\u003e2\u003c/sup\u003e, [Baigui Sun](https://scholar.google.co.id/citations?user=ZNhTHywAAAAJ\u0026hl=zh-CN)\u003csup\u003e2\u003c/sup\u003e, [Stan Z. Li](https://scholar.google.com/citations?user=Y-nyLGIAAAAJ\u0026hl=zh-CN)\u003csup\u003e†,1\u003c/sup\u003e\n\n\u003csup\u003e1\u003c/sup\u003e[Westlake University](https://westlake.edu.cn/), \u003csup\u003e2\u003c/sup\u003e[Damo Academy](https://damo.alibaba.com/?language=en), \u003csup\u003e3\u003c/sup\u003e[Zhejiang University](https://www.zju.edu.cn/english/)\n\u003c/div\u003e\n\n\u003cp align=\"center\"\u003e\n\u003ca href=\"https://arxiv.org/abs/2402.09240\" alt=\"arXiv\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/arXiv-2402.09240-b31b1b.svg?style=flat\" /\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/Westlake-AI/SEMA/blob/main/LICENSE\" alt=\"license\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/license-Apache--2.0-%23B7A800\" /\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n\u003c!-- Introduction --\u003e\n\n## Introduction\n\nExponential Moving Average (EMA) is a widely used weight averaging (WA) regularization to learn flat optima for better generalizations without extra cost in deep neural network (DNN) optimization. Despite achieving better flatness, existing WA methods might fall into worse final performances or require extra test-time computations. This work unveils the full potential of EMA with a single line of modification, i.e., switching the EMA parameters to the original model after each epoch, dubbed as Switch EMA (SEMA). From both theoretical and empirical aspects, we demonstrate that SEMA can help DNNs to reach generalization optima that better trade-off between flatness and sharpness. To verify the effectiveness of SEMA, we conduct comparison experiments with discriminative, generative, and regression tasks on vision and language datasets, including image classification, self-supervised learning, object detection and segmentation, image generation, video prediction, attribute regression, and language modeling. Comprehensive results with popular optimizers and networks show that SEMA is a free lunch for DNN training by improving performances and boosting convergence speeds.\n\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"https://github.com/Westlake-AI/openmixup/assets/44519745/5d6698c8-d189-4095-8076-d32ee59fdc57\" width=95% \nclass=\"center\"\u003e\n\u003c/p\u003e\n\n## Catalog\n\nThis repo is mainly based on [OpenMixup](https://github.com/Westlake-AI/openmixup) to implement classification, self-supervised learning, and regression tasks while using [MMDetection](https://github.com/open-mmlab/mmdetection/), DDPM, [OpenSTL](https://github.com/chengtan9907/OpenSTL), and [fairseq](https://github.com/facebookresearch/fairseq) for other tasks. **Please watch us for the latest release!**\n\u003c!-- Currently, this repo is reimplemented according to our official implementations in [OpenMixup](https://github.com/Westlake-AI/openmixup), and we are working on cleaning up experimental results and code implementations. Models are released in [GitHub](https://github.com/Westlake-AI/MogaNet/releases) / [Baidu Cloud](https://pan.baidu.com/s/1d5MTTC66gegehmfZvCQRUA?pwd=z8mf) / [Hugging Face](https://huggingface.co/MogaNet). --\u003e\n\n- [x] **Image Classification** on ImageNet-1K and CIFAR-100 in [OpenMixup](https://github.com/Westlake-AI/openmixup/tree/main/configs/classification/imagenet/). [[configs](classification/)]\n- [x] **Self-supervised Learning** with Contrastive Learning Methods in [OpenMixup](https://github.com/Westlake-AI/openmixup/tree/main/configs/selfsup).\n- [x] **Self-supervised Learning** with Masked Image Modeling Methods in [OpenMixup](https://github.com/Westlake-AI/openmixup/tree/main/configs/selfsup).\n- [ ] **Object Detection and Segmentation** on COCO. [[code](detection/)]\n- [ ] **Image Generation** on CIFAR-10 and CelebA-Align. [[code](image_generation/)]\n- [ ] **Visual Regression** on AgeDB, IMDB-WIKI, and RCFMNIST in [OpenMixup](https://github.com/Westlake-AI/openmixup/tree/main/configs/regression).\n- [ ] **Video Prediction** on Moving-MNIST [[code](video_prediction/)].\n\n## Installation\nPlease check [INSTALL.md](./openmixup/docs/en/install.md) for installation instructions.\n\n## Experimental Results\nTODO!\n\n\u003cp align=\"right\"\u003e(\u003ca href=\"#top\"\u003eback to top\u003c/a\u003e)\u003c/p\u003e\n\n## License\n\nThis project is released under the [Apache 2.0 license](LICENSE).\n\n## Acknowledgement\n\nOur implementation is mainly based on the following codebases. We gratefully thank the authors for their wonderful works.\n\n- [OpenMixup](https://github.com/Westlake-AI/openmixup): Open-source toolbox for visual representation learning.\n- [MMDetection](https://github.com/open-mmlab/mmdetection): OpenMMLab Detection Toolbox and Benchmark.\n- [OpenSTL](https://github.com/chengtan9907/OpenSTL): A Comprehensive Benchmark of Spatio-Temporal Predictive Learning.\n- [fairseq](https://github.com/facebookresearch/fairseq): Facebook AI Research Sequence-to-Sequence Toolkit written in Python.\n\n## Citation\n\nIf you find this repository helpful, please consider citing:\n```\n@inproceedings{Li2024SwitchEMA,\n  title={Switch EMA: A Free Lunch for Better Flatness and Sharpness},\n  author={Siyuan Li and Zicheng Liu and Juanxi Tian and Ge Wang and Zedong Wang and Weiyang Jin and Di Wu and Cheng Tan and Tao Lin and Yang Liu and Baigui Sun and Stan Z. Li},\n  year={2024},\n}\n```\n\n\u003cp align=\"right\"\u003e(\u003ca href=\"#top\"\u003eback to top\u003c/a\u003e)\u003c/p\u003e\n","funding_links":[],"categories":["Python"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FWestlake-AI%2FSEMA","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FWestlake-AI%2FSEMA","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FWestlake-AI%2FSEMA/lists"}