Skip to main content

A fast and efficient implimentation of progressive sprinkles augmentation.

Project description

tf_sprinkles

Sprinkles augmentation implemented in TensorFlow

Based on Less Wright's Medium article, Progessive Sprinkles: a New Data Augmentation for CNNs. See also his post on fast.ai.

To install:

pip install tf_sprinkles

To use:

from tf_sprinkles import Sprinkles
sprinkles = Sprinkles(num_holes, side_length)

Then call sprinkles(image) in the input pipeline for your image. A simple example to get started using the cat.jpeg image located in the data folder is:

import numpy as np
import tensorflow as tf
from tf_sprinkles import Sprinkles
from PIL import Image
from matplotlib import pyplot as plt

sprinkles = Sprinkles(num_holes=100, side_length=10)
img = Image.open('data/cat.jpeg')
img = np.asarray(img) / 255.
result = sprinkles(tf.constant(img, dtype=tf.float32))
plt.imshow(result.numpy())

Which results in the following image with sprinkles.

cat with sprinkles

Note that the mode flag added in version 1.1.0 can be used to specify that sprinkles should be filled with Gaussian noise (mode='gaussian'), randomly filled with black or white (mode='salt_pepper'), or all black (the default or mode=None).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tf_sprinkles-1.1.0.tar.gz (3.6 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page