Giter Site home page Giter Site logo

gridmixup's Introduction

GridMixup

A GridMixup augmentation, inspired by GridMask and CutMix

Easy install

pip install git+https://github.com/IlyaDobrynin/GridMixup.git

Overview

This simple augmentation is inspired by the GridMask and CutMix augmentations. The combination of this two augmentations forms proposed method.

Example

To run simple examples notebooks, you should install requirements:

pip install -r requirements.txt

Simple examples are here: demo and pipeline demo

TlDr:

from gridmix import GridMixupLoss

gridmix_cls = GridMixupLoss(
    alpha=(0.4, 0.7),
    hole_aspect_ratio=1.,
    crop_area_ratio=(0.5, 1),
    crop_aspect_ratio=(0.5, 2),
    n_holes_x=(2, 6)
)

images, targets = batch['images'], batch['targets']
images_mixed, targets_mixed = gridmix_cls.get_sample(images=images, targets=targets)
preds = model(images_mixed)
loss = criterion(preds, targets_mixed) 

Before

After

GridMixup loss defined as:

lam * CrossEntropyLoss(preds, trues1) + (1 - lam) * CrossEntropyLoss(preds, trues2)

where:

  • lam - the area of the main image
  • (1 - lam) - area of the secondary image

Parameters

GridMixupLoss takes follow arguments:

  • alpha - parameter define area of the main image in mixed image. Could be float or Tuple[float, float].
    • if float: lambda parameter gets from the beta-dictribution np.random.beta(alpha, alpha);
    • if Tuple[float, float]: lambda parameter gets from the uniform distribution np.random.uniform(alpha[0], alpha[1]).
  • n_holes_x - number of holes in crop by X axis.
  • hole_aspect_ratio - aspect ratio of holes.
  • crop_area_ratio - parameter define area of the secondary image on a mixed image.
  • crop_aspect_ratio - aspect ratio of crop.

gridmixup's People

Contributors

ilyadobrynin 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.