{"id":13709048,"url":"https://github.com/JunlinHan/CropMix","last_synced_at":"2025-05-06T15:32:11.517Z","repository":{"id":61054253,"uuid":"497201105","full_name":"JunlinHan/CropMix","owner":"JunlinHan","description":"Code of CropMix: Sampling a Rich Input Distribution via Multi-Scale Cropping","archived":false,"fork":false,"pushed_at":"2022-10-08T16:59:04.000Z","size":2066,"stargazers_count":17,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-11-13T19:39:32.622Z","etag":null,"topics":["computer-vision","contrastive-learning","data-augmentation","deep-learning","image-classification","machine-learning","masked-image-modeling","representation-learning","self-supervised-learning"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","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/JunlinHan.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}},"created_at":"2022-05-28T03:22:37.000Z","updated_at":"2024-09-18T07:34:36.000Z","dependencies_parsed_at":"2022-10-09T08:41:19.845Z","dependency_job_id":null,"html_url":"https://github.com/JunlinHan/CropMix","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/JunlinHan%2FCropMix","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JunlinHan%2FCropMix/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JunlinHan%2FCropMix/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JunlinHan%2FCropMix/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JunlinHan","download_url":"https://codeload.github.com/JunlinHan/CropMix/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252713014,"owners_count":21792410,"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":["computer-vision","contrastive-learning","data-augmentation","deep-learning","image-classification","machine-learning","masked-image-modeling","representation-learning","self-supervised-learning"],"created_at":"2024-08-02T23:00:35.435Z","updated_at":"2025-05-06T15:32:06.500Z","avatar_url":"https://github.com/JunlinHan.png","language":"Jupyter Notebook","funding_links":[],"categories":["Self-Supervised Learning"],"sub_categories":["**Contrastive Learning**"],"readme":"# CropMix\n\nCropMix is a method for sampling input distribution. CropMix captures multi-scale information from the dataset distribution to form a richer input distribution for vision tasks. Compared to RRC (Random Resized Crop), CropMix shows positive results in image classification, contrastive learning, and masked image modeling. \n\n[CropMix: Sampling a Rich Input Distribution via Multi-Scale Cropping](https://arxiv.org/abs/2205.15955) \u003cbr\u003e\n[Junlin Han](https://junlinhan.github.io/), [Lars Petersson](https://people.csiro.au/P/L/Lars-Petersson), [Hongdong Li](http://users.cecs.anu.edu.au/~hongdong/), [Ian Reid](https://cs.adelaide.edu.au/~ianr/) \u003cbr\u003e\nDATA61-CSIRO and Australian National University and University of Adelaide \u003cbr\u003e\nPreprint, 2022\n\n```\n@inproceedings{han2022cropmix,\n  title={CropMix: Sampling a Rich Input Distribution via Multi-Scale Cropping},\n  author={Junlin Han and Lars Petersson and Hongdong Li and Ian Reid},\n  booktitle={arXiv preprint arXiv:2205.15955},\n  year={2022}\n}\n```\n\nCropMix utilizes multiple cropping operations with distinct crop scales to obtain multiple cropped views. Gradually mixing these cropped views produces a mixed\nimage containing multi-scale information. \n\n\u003cimg src='imgs/cropmix.png' align=\"middle\" width=800\u003e\n\n## Easy usages\nThis is a demo of employing CropMix to create your training dataset. \n```\nimport torchvision.transforms as transforms\nimport torchvision.datasets as datasets\nimport cropmix\n\n# CropMix configurations\nparser.add_argument('--scale', default=0.01, type=float,\n                    help='min crop scale')\nparser.add_argument('--mix_ratio', default=0.4, type=float,\n                    help='mixing ratio/weight for mixup')\nparser.add_argument('--number', default=234, type=int,\n                    help='number of crops/cropping operations. support 2, 3, 4 and 234, where 234 is for (2,3,4)')\nparser.add_argument('--operation', default=0, type=int,\n                    help='mixing operation, 0 for mixup, 1 for cutmix')\nparser.add_argument('--inter_aug', action='store_true',\n                    help='apply intermediate augmentation (channel permutation)')\n\n# path to your dataset\ntraindir = os.path.join(args.data, 'train')\n\n# post augmentation, usually horizontal flip and normalization\npost_aug = transforms.Compose([\n    transforms.RandomHorizontalFlip(),\n])\n\n# create your training dataset with cropmix\ntrain_dataset = datasets.ImageFolder(\n    traindir,\n    cropmix.CropMix(args.scale, args.mix_ratio, args.number, args.operation, args.inter_aug,  post_aug))\n\n```\n\n## Prerequisites\nThis repo aims to be minimal modifications on [official PyTorch ImageNet training code](https://github.com/pytorch/examples/tree/master/imagenet), [asym-siam](https://github.com/facebookresearch/asym-siam), and [mae](https://github.com/facebookresearch/mae). Following their instructions to install the environments and prepare the datasets.\n\n[timm](https://github.com/rwightman/pytorch-image-models) is also required for ImageNet classification, simply run\n\n```\npip install timm==0.3.2\n```\n\n## CropMix and RRC visualization\n\u003cimg src='imgs/visu.png' align=\"middle\" width=800\u003e\n\n## Results\nHere we present some results of applying CropMix on three vision tasks, please see our paper for full results. \n\nImageNet classification:\n\n\u003cimg src='imgs/classification.png' align=\"middle\" width=800\u003e\n\nContrastive learning:\n\n\u003cimg src='imgs/contrastive.png' align=\"middle\" width=800\u003e\n\nMasked image modeling:\n\n\u003cimg src='imgs/mim.png' align=\"middle\" width=400 height= 220\u003e \u003cimg src='imgs/mim2.png' align=\"middle\" width=400 height= 220\u003e\n\n## Training and testing\nPlease see each sub-folder for detailed instructions.\n\n## Contact\njunlin.han@data61.csiro.au or junlinhcv@gmail.com\n\nIf you tried CropMix in other tasks and datasets, please feel free to let me know the results. They will be collected and presented in this repo, regardless of positive or negative. Thank you!\n\n## Acknowledgments\nOur code is developed based on [official PyTorch ImageNet training code](https://github.com/pytorch/examples/tree/master/imagenet), [asym-siam](https://github.com/facebookresearch/asym-siam),  [mae](https://github.com/facebookresearch/mae), and [YOCO](https://github.com/JunlinHan/YOCO). This repo borrows heavily from [YOCO](https://github.com/JunlinHan/YOCO).\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FJunlinHan%2FCropMix","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FJunlinHan%2FCropMix","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FJunlinHan%2FCropMix/lists"}