Created
July 24, 2017 11:15
-
-
Save dnkirill/f4bd8069182ab8108d18a7a17ab5121b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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