Giter Site home page Giter Site logo

keras-ricap's Introduction

A Keras/TensorFlow implementation of RICAP

This repository is Keras's implementation of RICAP(Random Image Cropping And Patching), Data Augmentation algorithm which achieved SoTA with CIFAR-10 at error rate 2.19%. We applied to animeface-character-dataset.

How to use

It is easy to inherit from ImageDataGenerator of Keras like this:

from keras.preprocessing.image import ImageDataGenerator
from ricap import ricap

# RICAP Generator
class RICAPGenerator(ImageDataGenerator):
    def __init__(self, ricap_beta=0.3, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.ricap_beta = ricap_beta

    def flow_from_directory(self, *args, **kwargs):
        for batch_X, batch_y in super().flow_from_directory(*args, **kwargs):
            ricap_X, ricap_y = ricap(batch_X, batch_y, self.ricap_beta)
            yield ricap_X, ricap_y

Use same random numbers with beta distribution in batch vs. Use different random numbers for each sample

There are 2 versions here.

  1. Use same random numbers in batch (default, same as the paper)
  2. Use different random numbers for each sample (made it on our own)

If you want to try differnt random numbers version, please specify use_same_random_value_on_batch=False

Same version

Different version

Results

Conditions Test Accuracy
baseline 91.5039%
batchwise RICAP (original) beta=0.1 91.7236%
batchwise RICAP (original) beta=0.3 92.3340%
batchwise RICAP (original) beta=0.5 91.6748%
samplewise RICAP (changed) beta=0.1 92.0898%
samplewise RICAP (changed) beta=0.3 91.9922%
samplewise RICAP (changed) beta=0.5 91.6504%

Accuracy is better for batchwise(the original), but samplewise is smoother in error.

Beta scheduling

Also, we tried a method to schedule and change the beta value (a method close to the pseudo label of semi supervised learning).

example:

  • beta=0.01 if epoch<=20
  • increase beta value linearly if 20<epoch<=90
  • beta=1 if epoch>90 (i.e. uniform distribution)

On beta scheduling, it seems that samplewise RICAP is better.

Refence

Ryo Takahashi, Takashi Matsubara, Kuniaki Uehara. Data Augmentation using Random Image Cropping and Patching for Deep CNNs. ACML2018. 2018

keras-ricap's People

Contributors

koshian2 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

keras-ricap's Issues

input for ricap?

Hello, may I ask what is the batch_x and batch_y for ricap? Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.