Home

Awesome

cutmix

<img src="https://github.com/clovaai/CutMix-PyTorch/raw/master/img1.PNG" width=50% />

a Ready-to-use PyTorch Extension of Unofficial CutMix Implementations.

This re-implementation is improved in some parts,

Hence, there may be slightly-improved training results also.

Requirements

Install

This repository is pip-installable,

$ pip install git+https://github.com/ildoonet/cutmix

or you can copy 'cutmix' folder to your project to use it.

Usage

Our CutMix is inhereted from the PyTorch Dataset class so you can wrap your own dataset(eg. cifar10, imagenet, ...). Also we provide CutMixCrossEntropyLoss, soft version of cross-entropy loss, which accept soft-labels required by cutmix.

from cutmix.cutmix import CutMix
from cutmix.utils import CutMixCrossEntropyLoss
...

dataset = datasets.CIFAR100(args.cifarpath, train=True, download=True, transform=transform_train)
dataset = CutMix(dataset, num_class=100, beta=1.0, prob=0.5, num_mix=2)    # this is paper's original setting for cifar.
...

criterion = CutMixCrossEntropyLoss(True)
for _ in range(num_epoch):
    for input, target in loader:    # input is cutmixed image's normalized tensor and target is soft-label which made by mixing 2 or more labels.
        output = model(input)
        loss = criterion(output, target)
    
        loss.backward()
        optimizer.step()
        optimizer.zero_grad()

Result

PyramidNet-200 + ShakeDrop + CutMix \w CIFAR-100

Top-1 Error(@300epoch)Top-1 Error(Best)Model File
Paper's Reported ResultN/A13.81N/A
Our Re-implementation13.6813.15Download(12.88)
+ Fast AutoAugment13.312.95

We ran 6 indenpendent experiments with our re-implemented codes and got top-1 errors of 13.09, 13.29, 13.27, 13.24, 13.15 and 12.88, using below command. (Converged at 300epoch with the top-1 errors of 13.55, 13.66, 13.95, 13.9, 13.8 and 13.32.)

$ python train.py -c conf/cifar100_pyramid200.yaml

ResNet + CutMix \w ImageNet

Top-1 Error<br/>(@300epoch)Top-1 Error<br/>(Best)Model File
ResNet18Reported Result \wo CutMixN/A30.43
Ours29.67429.56
ResNet34Reported Result \wo CutMixN/A26.456
Ours24.724.57Download
ResNet50Paper's Reported ResultN/A21.4N/A
Author's Code(Our Re-run)21.76821.586N/A
Our Re-implementation21.52421.340Download(21.25)
ResNet200Our Re-implementation
+ Fast AutoAugment19.05818.858
$ python train.py -c conf/imagenet_resnet50.yaml

We ran 5 independent experiments on ResNet50.

Reference