https://github.com/JunlinHan/YOCO
Code for You Only Cut Once: Boosting Data Augmentation with a Single Cut, ICML 2022.
https://github.com/JunlinHan/YOCO
cifar10 cifar100 classification computer-vision contrastive-learning data-augmentation data-augmentation-strategies data-augmentations icml imagenet imagenet-classifier instance-segmentation object-detection pytorch rain-removal super-resolution
Last synced: about 2 months ago
JSON representation
Code for You Only Cut Once: Boosting Data Augmentation with a Single Cut, ICML 2022.
- Host: GitHub
- URL: https://github.com/JunlinHan/YOCO
- Owner: JunlinHan
- Created: 2022-01-27T13:59:57.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-08-01T09:05:26.000Z (about 2 years ago)
- Last Synced: 2024-12-16T02:34:22.008Z (10 months ago)
- Topics: cifar10, cifar100, classification, computer-vision, contrastive-learning, data-augmentation, data-augmentation-strategies, data-augmentations, icml, imagenet, imagenet-classifier, instance-segmentation, object-detection, pytorch, rain-removal, super-resolution
- Language: Python
- Homepage:
- Size: 5.3 MB
- Stars: 104
- Watchers: 4
- Forks: 10
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- Awesome-Mixup - [Code
README
# You Only Cut Once (YOCO)
YOCO is a simple method/strategy of performing augmentations, which enjoys the properties of parameter-free, easy usage, and boosting almost all augmentations for free (negligible computation & memory cost).
[You Only Cut Once: Boosting Data Augmentation with a Single Cut](https://arxiv.org/abs/2201.12078)
[Junlin Han](https://junlinhan.github.io/), Pengfei Fang, Weihao Li, Jie Hong, Ali Armin, [Ian Reid](https://cs.adelaide.edu.au/~ianr/), [Lars Petersson](https://people.csiro.au/P/L/Lars-Petersson), [Hongdong Li](http://users.cecs.anu.edu.au/~hongdong/)
DATA61-CSIRO and Australian National University and University of Adelaide
International Conference on Machine Learning (ICML), 2022```
@inproceedings{han2022yoco,
title={You Only Cut Once: Boosting Data Augmentation with a Single Cut},
author={Junlin Han and Pengfei Fang and Weihao Li and Jie Hong and Mohammad Ali Armin and and Ian Reid and Lars Petersson and Hongdong Li},
booktitle={International Conference on Machine Learning (ICML)},
year={2022}
}
```
YOCO cuts one image into two equal pieces, either in the height or the width dimension. The same data augmentations are performed independently within each piece. Augmented pieces are then concatenated together to form the final augmented image.![]()
## ResultsOverall, YOCO benefits almost all augmentations in multiple vision tasks (classification, contrastive learning, object detection, instance segmentation, image deraining, image super-resolution). Please see our paper for more.
## Easy usages
Applying YOCO is quite easy, here is a demo code of performing YOCO at the batch level.
```
***
images: images to be augmented, here is tensor with (b,c,h,w) shape
aug: composed augmentation operations, we use horizontal flip here
h: height of images
w: width of images
***def YOCO(images, aug, h, w):
images = torch.cat((aug(images[:, :, :, 0:int(w/2)]), aug(images[:, :, :, int(w/2):w])), dim=3) if \
torch.rand(1) > 0.5 else torch.cat((aug(images[:, :, 0:int(h/2), :]), aug(images[:, :, int(h/2):h, :])), dim=2)
return images
for i, (images, target) in enumerate(train_loader):
aug = torch.nn.Sequential(
transforms.RandomHorizontalFlip(), )
_, _, h, w = images.shape
# perform augmentations with YOCO
images = YOCO(images, aug, h, w)
```
You may use any [pytorch inbuilt augmentation operations](https://pytorch.org/vision/stable/transforms.html) to replace the horizontal flip operation.## Prerequisites
This repo aims to be minimal modifications on [official PyTorch ImageNet training code](https://github.com/pytorch/examples/tree/master/imagenet) and [MoCo](https://github.com/facebookresearch/moco). Following their instructions to install the environments and prepare the datasets.
[timm](https://github.com/rwightman/pytorch-image-models) is also required for ImageNet classification, simply run
```
pip install timm
```
## Images augmented with YOCO
For each quadruplet, we show the original input image, augmented image from image-level augmentation, and two images from different cut dimensions produced by YOCO.## Contact
junlinhcv@gmail.comIf you tried YOCO in other tasks/datasets/augmentations, please feel free to let me know the results. They will be collected and presented in this repo, regardless of positive or negative. Many thanks!
## Acknowledgments
Our code is developed based on [official PyTorch ImageNet training code](https://github.com/pytorch/examples/tree/master/imagenet) and [MoCo](https://github.com/facebookresearch/moco). We thank anonymous reviewers for their invaluable feedback!