Skip to content

Instantly share code, notes, and snippets.

@dnkirill
Created July 24, 2017 11:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dnkirill/f4bd8069182ab8108d18a7a17ab5121b to your computer and use it in GitHub Desktop.
Save dnkirill/f4bd8069182ab8108d18a7a17ab5121b to your computer and use it in GitHub Desktop.
import pandas as pd
# Generate an augmented dataset using a transform table
augmentation_table = pd.read_csv('augmentation_table.csv', index_col='label_class')
augmentation_table.drop('label_name', axis=1, inplace=True)
augmentation_table.dropna(axis=0, how='all', inplace=True)
# Collect all global functions in global namespace
namespace = __import__(__name__)
def apply_augmentation(X, how=None):
"""Apply an augmentation function specified in `how` (string) to a numpy array X.
Args:
X: numpy array with images.
how: a string with a function name to be applied to X, should return
the same-shaped numpy array as in X.
Returns:
Augmented X dataset.
"""
assert augmentation_table.get(how) is not None
augmentator = getattr(namespace, how)
return augmentator(X)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment