{"id":13578435,"url":"https://github.com/Shaoli-Huang/SnapMix","last_synced_at":"2025-04-05T19:33:06.409Z","repository":{"id":217509941,"uuid":"319199536","full_name":"Shaoli-Huang/SnapMix","owner":"Shaoli-Huang","description":"SnapMix: Semantically Proportional Mixing for Augmenting Fine-grained Data (AAAI 2021)","archived":false,"fork":false,"pushed_at":"2020-12-26T05:12:44.000Z","size":867,"stargazers_count":129,"open_issues_count":4,"forks_count":25,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-11-05T16:45:27.554Z","etag":null,"topics":["aaai2021","cutmix","data-augmentation","fine-grained-recognition","mixup"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Shaoli-Huang.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2020-12-07T04:04:04.000Z","updated_at":"2024-09-08T14:37:52.000Z","dependencies_parsed_at":"2024-01-16T23:47:26.372Z","dependency_job_id":null,"html_url":"https://github.com/Shaoli-Huang/SnapMix","commit_stats":null,"previous_names":["shaoli-huang/snapmix"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Shaoli-Huang%2FSnapMix","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Shaoli-Huang%2FSnapMix/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Shaoli-Huang%2FSnapMix/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Shaoli-Huang%2FSnapMix/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Shaoli-Huang","download_url":"https://codeload.github.com/Shaoli-Huang/SnapMix/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247392959,"owners_count":20931801,"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":["aaai2021","cutmix","data-augmentation","fine-grained-recognition","mixup"],"created_at":"2024-08-01T15:01:30.631Z","updated_at":"2025-04-05T19:33:06.399Z","avatar_url":"https://github.com/Shaoli-Huang.png","language":"Python","funding_links":[],"categories":["Python","Table of Contents"],"sub_categories":["**Saliency Token**"],"readme":"# SnapMix: Semantically Proportional Mixing for Augmenting Fine-grained Data (AAAI 2021)\n\nPyTorch implementation of SnapMix | [paper](https://arxiv.org/abs/2012.04846)\n\n## Method Overview\n\n![SnapMix](./imgs/overview.jpg)\n\n## Cite\n```\n@inproceedings{huang2021snapmix,\n    title={SnapMix: Semantically Proportional Mixing for Augmenting Fine-grained Data},\n    author={Shaoli Huang, Xinchao Wang, and Dacheng Tao},\n    year={2021},\n    booktitle={AAAI Conference on Artificial Intelligence},\n}\n```\n\n## Setup\n### Install Package Dependencies\n```\ntorch\ntorchvision \nPyYAML\neasydict\ntqdm\nscikit-learn\nefficientnet_pytorch\npandas\nopencv\n```\n### Datasets\n***create a soft link to the dataset directory***\n\nCUB dataset\n```\nln -s /your-path-to/CUB-dataset data/cub\n```\nCar dataset\n```\nln -s /your-path-to/Car-dataset data/car\n```\nAircraft dataset\n```\nln -s /your-path-to/Aircraft-dataset data/aircraft\n```\n\n## Training\n\n### Training with Imagenet pre-trained weights\n\n\n***1. Baseline and Baseline+***\n\nTo train a model on CUB dataset using the Resnet-50 backbone, \n\n``` python main.py ```   # baseline\n\n``` python main.py --midlevel```  # baseline+\n\nTo train model on other datasets using other network backbones, you can specify the following arguments: \n\n``` --netname: name of network architectures (support 4 network families: ResNet,DenseNet,InceptionV3,EfficientNet) ```\n\n``` --dataset: dataset name```\n\nFor example, \n\n``` python main.py --netname resnet18 --dataset cub ```   # using the Resnet-18 backbone on CUB dataset\n\n``` python main.py --netname efficientnet-b0 --dataset cub ```   # using the EfficientNet-b0 backbone on CUB dataset\n\n``` python main.py --netname inceptoinV3 --dataset aircraft ```  # using the inceptionV3 backbone on Aircraft dataset\n\n\n***2. Training with mixing augmentation***\n\nApplying SnapMix in training ( we used the hyperparameter values (prob=1., beta=5) for SnapMix in most of the experiments.):\n\n```python main.py --mixmethod snapmix --beta 5 --netname resnet50 --dataset cub ``` # baseline \n\n```python main.py --mixmethod snapmix --beta 5 --netname resnet50 --dataset cub --midlevel ``` # baseline+ \n\nApplying other augmentation methods (currently support cutmix,cutout,and mixup) in training:\n\n```python main.py --mixmethod cutmix --beta 3 --netname resnet50 --dataset cub ```   # training with CutMix\n\n```python main.py --mixmethod mixup --prob 0.5 --netname resnet50 --dataset cub ```  # training with MixUp\n\n***3. Results***\n\n***ResNet architecture.***\n\n|  Backbone | Method | CUB   | Car    |   Aircraft |  \n|:--------|:--------|--------:|------:|--------:|\n|Resnet-18 | Baseline| 82.35% |  91.15% | 87.80% |  \n|Resnet-18 | Baseline + SnapMix| 84.29% |  93.12% | 90.17% |\n|Resnet-34 | Baseline| 84.98% |  92.02% | 89.92% |  \n|Resnet-34 | Baseline + SnapMix| 87.06% |  93.95% | 92.36% |\n|Resnet-50 | Baseline| 85.49% |  93.04% | 91.07% |  \n|Resnet-50 | Baseline + SnapMix| 87.75% |  94.30% | 92.08% |\n|Resnet-101 | Baseline| 85.62% |  93.09% | 91.59% |  \n|Resnet-101 | Baseline + SnapMix| 88.45% |  94.44% | 93.74% |\n|Resnet-50 | Baseline+| 87.13% |  93.80% | 91.68% |  \n|Resnet-50 | Baseline+ + SnapMix| 88.70% |  95.00% | 93.24% |\n|Resnet-101 | Baseline+| 87.81% |  93.94% | 91.85% |  \n|Resnet-101 | Baseline+ + SnapMix| 89.32% |  94.84% | 94.05% |\n\n\n***InceptionV3 architecture.***\n\n|  Backbone | Method | CUB   | \n|:--------|:--------|--------:|\n|InceptionV3 | Baseline| 82.22% |\n|InceptionV3 | Baseline + SnapMix| 85.54%|\n\n\n***DenseNet architecture.***\n\n|  Backbone | Method | CUB   | \n|:--------|:--------|--------:|\n|DenseNet121 | Baseline| 84.23% |  \n|DenseNet121| Baseline + SnapMix| 87.42%|\n\n\n### Training from scratch\n\nTo train a model without using ImageNet pretrained weights:\n\n```python main.py --mixmethod snapmix --prob 0.5 --netname resnet18 --dataset cub --pretrained 0``` # resnet-18 backbone\n\n```python main.py --mixmethod snapmix --prob 0.5 --netname resnet50 --dataset cub --pretrained 0 ``` # resnet-50 backbone\n\n***2. Results***\n\n|  Backbone | Method | CUB   | \n|:--------|:--------|--------:|\n|Resnet-18 | Baseline| 64.98% |\n|Resnet-18 | Baseline + SnapMix| 70.31%|\n|Resnet-50 | Baseline| 66.92% |  \n|Resnet-50| Baseline + SnapMix| 72.17%|\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FShaoli-Huang%2FSnapMix","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FShaoli-Huang%2FSnapMix","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FShaoli-Huang%2FSnapMix/lists"}