Skip to content

Instantly share code, notes, and snippets.

@vertix
vertix / tf_data_augmentation_on_gpu.py
Last active April 9, 2022 20:55
TF data augmentation on GPU
def augment(images, labels,
resize=None, # (width, height) tuple or None
horizontal_flip=False,
vertical_flip=False,
rotate=0, # Maximum rotation angle in degrees
crop_probability=0, # How often we do crops
crop_min_percent=0.6, # Minimum linear dimension of a crop
crop_max_percent=1., # Maximum linear dimension of a crop
mixup=0): # Mixup coeffecient, see https://arxiv.org/abs/1710.09412.pdf
if resize is not None:
@vertix
vertix / tf_models_preprocessing.py
Last active June 3, 2018 15:08
Using tf_models.slim.preprocessing
# You need to add your local TF-models slim directory to PYTHON_PATH
# or just run script from this directory.
import tensorflow as tf
from preprocessing import inception_preprocessing
# you can use any uint8 tensor of matching dimensions
single_image = tf.placeholder(tf.uint8, shape=(None, None, 3))
# Augmentation operations are created here
augmented_image = inception_preprocessing.preprocess_image(