{"id":18653307,"url":"https://github.com/roatienza/agmax","last_synced_at":"2025-04-11T16:32:21.255Z","repository":{"id":127929964,"uuid":"250741636","full_name":"roatienza/agmax","owner":"roatienza","description":"PyTorch code of my WACV 2022 paper Improving Model Generalization by Agreement of Learned Representations from Data Augmentation","archived":false,"fork":false,"pushed_at":"2023-01-10T01:35:33.000Z","size":894,"stargazers_count":12,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-25T16:12:06.688Z","etag":null,"topics":["data-augmentation","generalization","regularization","wacv2022"],"latest_commit_sha":null,"homepage":"","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/roatienza.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-03-28T07:53:12.000Z","updated_at":"2024-07-31T07:56:06.000Z","dependencies_parsed_at":null,"dependency_job_id":"f874c10a-7359-402f-947d-46c079e9dbcf","html_url":"https://github.com/roatienza/agmax","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roatienza%2Fagmax","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roatienza%2Fagmax/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roatienza%2Fagmax/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roatienza%2Fagmax/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/roatienza","download_url":"https://codeload.github.com/roatienza/agmax/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248441285,"owners_count":21103958,"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":["data-augmentation","generalization","regularization","wacv2022"],"created_at":"2024-11-07T07:11:05.706Z","updated_at":"2025-04-11T16:32:21.239Z","avatar_url":"https://github.com/roatienza.png","language":"Python","readme":"# Improving Model Generalization by Agreement of Learned Representations from Data Augmentation\n\n### Paper\n\n* [WACV 2022](https://openaccess.thecvf.com/content/WACV2022/papers/Atienza_Improving_Model_Generalization_by_Agreement_of_Learned_Representations_From_Data_WACV_2022_paper.pdf)\n* [ArXiv](https://arxiv.org/abs/2110.10536)\n\n\n## Why it matters?\n\nWhen data augmentation is applied on an input image, a model is forced to learn invariant features to improve model generalization (Figure 1). \n\n\u003cimg src=\"https://github.com/roatienza/agmax/blob/master/figures/fig1_agmax.png\" width=\"50%\" height=\"50%\"\u003e\n\n\nSince data augmentation incurs little overhead, why not generate 2 data augmented images (also known as 2 positive samples) from a given input. Then, force the model to agree on the common invariant features to support the correct label (Figure 2). It turns out that maximizing this agreement further improves model model generalization. We call our method *AgMax*.\n\n\n\u003cimg src=\"https://github.com/roatienza/agmax/blob/master/figures/fig2_agmax.png\" width=\"50%\" height=\"50%\"\u003e\n\nUnlike label smoothing, AgMax consistently improves model accuracy. For example on ImageNet1k for 90 epochs, the ResNet50 performance is as follows:\n\n\n| Data Augmentation | Baseline | Label Smoothing | AgMax (Ours) |\n| :------------ | :-------------: | :-------------: | :-------------: |\n| Standard | 76.4 | 76.8 | 76.9 | \n| CutOut | 76.2 | 76.5 | 77.1 |\n| MixUp | 76.5 | 76.7| **77.6**  |\n| CutMix | 76.3 | 76.4 | 77.4 |\n| AutoAugment (AA) | 76.2 | 76.2 | 77.1 |\n| CutOut+AA | 75.7 | 75.7 | 76.6 |\n| MixUp+AA | 75.9 | 76.5 | 77.1 |\n| CutMix+AA | 75.5 | 75.5 | 77.0 |\n\nThe figure below demonstrates consistent improvement across different data augmnentation methods:\n\n\u003cimg src=\"https://github.com/roatienza/agmax/blob/master/figures/ImageNet_ResNet50_90_epochs_Top-1.png\" width=\"50%\" height=\"50%\"\u003e\n\n\n\n### Install requirements\n\n```\npip3 install -r requirements.txt\n```\n\n### Train\n\nFor example, train ResNet50 with AgMax on 2 GPUs for 90 epochs, SGD with `lr=0.1` and multistep learning rate scheduler:\n\n```\nCUDA_VISIBLE_DEVICES=0,1 python3 main.py --config=ResNet50-standard-agmax --train \\\n--multisteplr --dataset=imagenet --epochs=90 --save\n```\n\nCompare the results without AgMax:\n\n```\nCUDA_VISIBLE_DEVICES=0,1 python3 main.py --config=ResNet50-standard --train \\\n--multisteplr --dataset=imagenet --epochs=90 --save\n```\n\n### Test\n\nUsing a pre-trained model:\n\nResNet101 trained with CutMix, AutoAugment and AgMax:\n```\nmkdir checkpoints\ncd checkpoints\nwget https://github.com/roatienza/agmax/releases/download/agmax-0.1.0/imagenet-agmax-mi-ResNet101-cutmix-auto_augment-81.19-mlp-4096.pth\ncd ..\npython3 main.py --config=ResNet101-auto_augment-cutmix-agmax --eval \\\n--dataset=imagenet \\\n--resume imagenet-agmax-mi-ResNet101-cutmix-auto_augment-81.19-mlp-4096.pth\n```\n\nResNet50 trained with CutMix, AutoAugment and AgMax:\n\n```\npython3 main.py --config=ResNet50-auto_augment-cutmix-agmax --eval --n-units=2048 \\\n--dataset=imagenet --resume imagenet-agmax-ResNet50-cutmix-auto_augment-79.12-mlp-2048.pth\n```\n\nOther pre-trained models (Baselines):\n\n- [ResNet101 Cutmix+AutoAugment](https://github.com/roatienza/agmax/releases/download/agmax-0.1.0/imagenet-standard-ResNet101-cutmix-auto_augment-80.69.pth)\n- [ResNet50 Cutmix+AutoAugment](https://github.com/roatienza/agmax/releases/download/agmax-0.1.0/imagenet-standard-ResNet50-cutmix-auto_augment-78.5.pth)\n\n## Citation\nIf you find this work useful, please cite:\n\n```\n@inproceedings{atienza2022improving,\n  title={Improving Model Generalization by Agreement of Learned Representations from Data Augmentation},\n  author={Atienza, Rowel},\n  booktitle={Proceedings of the IEEE/CVF Winter Conference on Applications of Computer Vision},\n  pages={372--381},\n  year={2022}\n}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Froatienza%2Fagmax","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Froatienza%2Fagmax","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Froatienza%2Fagmax/lists"}