Skip to content

Through this project we will try to understand CutMix by implementing it on a simple problem of cat-vs-dog classification.

License

Notifications You must be signed in to change notification settings

ar8372/CutMix-Regularization-Strategy-to-Train-Strong-Classifiers-with-Localizable-Features

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CutMix-Regularization

Through this project we will try to understand CutMix Augmentation by implementing it on a simple problem of cat-vs-dog classification.

Implementation

I have used keras to implement the cutmix augmentation. Dataset used: https://www.kaggle.com/competitions/dogs-vs-cats/data.
In CutMix we mix two images and their labels respectively in order to generate new data point. To implement this, I have created a custom datagenerator. This custom datagenerator takes batches from two seperate keras datagenerator and returns one batch by applying cutmix on it.

train datagenerator (custom)

train_dataset = CutMixImageDataGenerator(
    generator1= train_datagen1, #train_generator1,
    generator2= train_datagen2, #train_generator2,
    img_size=128,
    batch_size=32,
)

valid datagenerator (default)

valid_dataset = valid_datagen.flow_from_dataframe(
    dataframe=validate_df,
    directory=image_path,
    target_size=(128, 128), 
    x_col='filename', 
    y_col='category',
    batch_size=32,
    seed=42,
    shuffle=True,
    class_mode="categorical",  
    )

Results

Type Without CutMix With CutMix
Output
Training and Validation Accuracy plot
Score loss: 0.7671 - acc: 0.6406
val_loss: 0.9630 - val_acc: 0.6445
loss: 0.1226 - acc: 0.9538
val_loss: 0.4688 - val_acc: 0.8438
#epochs 50 50
Early Stop at 28 15

Conclusion

We have two notebooks 1. Without CutMix and 2. With CutMix. Both notebooks have everything exactly same(seed, batchsize, #epochs, rescaling etc) only except the training datagenerator. And we notice that using CutMix augmentation has really improved the validation score making the model more regularized and robust in comparision to model which is trained without using CutMix augmentation.

Reference

About

Through this project we will try to understand CutMix by implementing it on a simple problem of cat-vs-dog classification.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published