Giter Site home page Giter Site logo

mohammadreza-dz / cutout-random-erasing Goto Github PK

View Code? Open in Web Editor NEW

This project forked from yu4u/cutout-random-erasing

0.0 1.0 0.0 120 KB

Cutout / Random Erasing implementation, especially for ImageDataGenerator in Keras

License: MIT License

Python 12.93% Jupyter Notebook 87.07%

cutout-random-erasing's Introduction

Cutout / Random Erasing

This is a Cutout [1] / Random Erasing [2] implementation. In particular, it is easily used with ImageDataGenerator in Keras. Please check random_eraser.py for implementation details.

About Cutout / Random Erasing

Cutout or Random Erasing is a kind of image augmentation methods for convolutional neural networks (CNN). They are very similar methods and were proposed almost at the same time.

They try to regularize models using training images that are randomly masked with random values.

Usage

With ImageDataGenerator in Keras

It is very easy to use if you are using ImageDataGenerator in Keras; get eraser function by get_random_eraser(), and then pass it to ImageDataGenerator as preprocessing_function. By doing so, all images are randomly erased before standard augmentation done by ImageDataGenerator.

Please check cifar10_resnet.py, which is imported from official Keras examples.

What I did is adding only two lines:

...
from random_eraser import get_random_eraser  # added
...

    datagen = ImageDataGenerator(
    ...
        preprocessing_function=get_random_eraser(v_l=0, v_h=1))  # added

Erase a single image

Of cause, you can erase a single image using eraser function. Please note that eraser function works in inplace mode; the input image itself will be modified (therefore, img = eraser(img) can be replaced by eraser(img) in the following example).

from random_eraser import get_random_eraser
eraser = get_random_eraser()

# load image to img
img = eraser(img)

Pleae check example.ipynb for complete example.

Parameters

Parameters are fully configurable as:

get_random_eraser(p=0.5, s_l=0.02, s_h=0.4, r_1=0.3, r_2=1/0.3,
                  v_l=0, v_h=255, pixel_level=False)
  • p : the probability that random erasing is performed
  • s_l, s_h : minimum / maximum proportion of erased area against input image
  • r_1, r_2 : minimum / maximum aspect ratio of erased area
  • v_l, v_h : minimum / maximum value for erased area
  • pixel_level : pixel-level randomization for erased area

Results

The original cifar10_resnet.py result (w/o cutout / random erasing):

Test loss: 0.539187009859
Test accuracy: 0.9077

With cutout / random erasing:

Test loss: 0.445597583055
Test accuracy: 0.9182

With cutout / random erasing (pixel-level):

Test loss: 0.446407950497
Test accuracy: 0.9213

References

[1] T. DeVries and G. W. Taylor, "Improved Regularization of Convolutional Neural Networks with Cutout," in arXiv:1708.04552, 2017.

[2] Z. Zhong, L. Zheng, G. Kang, S. Li, and Y. Yang, "Random Erasing Data Augmentation," in arXiv:1708.04896, 2017.

cutout-random-erasing's People

Contributors

yu4u avatar kosuke55 avatar

Watchers

James Cloos avatar

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.