spacekit.generator.augment
- spacekit.generator.augment.aug_generator(X, c=9, combine=False)[source]
Generates randomly performed image augmentations. Optionally concatenates this data with original.
- Parameters:
- Returns:
randomly augmented image data (merged with original data if combine set to True).
- Return type:
numpy array
- spacekit.generator.augment.augment_data(xi)[source]
Randomly apply noise to input data. For now this function is designed for SVM ensemble MLP input data. For other uses, the function tries to determine which augmentation operation to apply according to the data type - however it may not make sense for all the inputs to be augmented (e.g. if they are binary/boolean) so this should be used with caution (future updates this will be generalized properly for other use cases).
- Parameters:
xi (numpy array) – 1d-array of input data
- Returns:
input data with random augmentations applied
- Return type:
numpy array
- spacekit.generator.augment.augment_image(x, c=None, w=128, h=128, ch=3, dim=3)[source]
Randomly applies a series of augmentation transformations. Except for random crops, random application is required to impose translational invariance.
- Parameters:
x (numpy array) – input image array
c (int, optional) – depth (product of dim and ch), by default None
w (int, optional) – image width, by default 128
h (int, optional) – image height, by default 128
ch (int, optional) – channels, by default 3
dim (int, optional) – dimensions (or volume of image frames per input), by default 3
- Returns:
random augmentation of input image
- Return type:
numpy array
- spacekit.generator.augment.augment_random_integer(x)[source]
Randomly apply augmentations to integer values. Assumes final values must be absolute/non-negative.
- spacekit.generator.augment.augment_random_noise(x)[source]
Random application of laplacian and/or logistic noise calculated relative to the input value. Augmentation transformations are applied randomly to impose translational invariance.
- spacekit.generator.augment.color_jitter(x, brightness=0.4, contrast=0.4, saturation=0.4, hue=None)[source]
Randomly applies a combination of alterations to the image brightness, contrast, saturation and hue. Note: a clipping function is performed at the end since affine transformations can disturb the natural range of RGB images.
- Parameters:
x (numpy array) – input image array
brightness (float, optional) – decimal percentage strength applied to brightness level, by default 0.4
contrast (float, optional) – decimal percentage strength applied to contrast level, by default 0.4
saturation (float, optional) – decimal percentage strength applied to saturation level, by default 0.4
hue (float, optional) – decimal percentage strength applied to hue (e.g. 0.1), by default None
- Returns:
transformed image input array
- Return type:
numpy array
- spacekit.generator.augment.expand_dims(X, dim=3, w=128, h=128, ch=3)[source]
Expand flattened array back into its constituent dimensions.
- Parameters:
- Returns:
numpy array of shape – Reshaped multi-dimensional image array
- Return type:
(X.shape[0], dim, w, h, ch)
- spacekit.generator.augment.flip_horizontal(x)[source]
Horizontal (x-axis) image flip
- Parameters:
x (numpy array) – input image array
- Returns:
horizontally flipped image
- Return type:
numpy array
- spacekit.generator.augment.flip_vertical(x)[source]
Vertical (y-axis) image flip
- Parameters:
x (numpy array) – input image array
- Returns:
vertically flipped image
- Return type:
numpy array
- spacekit.generator.augment.image_index_labels(index, y, aug=False)[source]
Creates Pandas Index and Series from numpy arrays (used for calculating FNFP data in
spacekit.analyzer.compute
)
- spacekit.generator.augment.laplacian_noise(x)[source]
Calculates laplacian value relative to the input.
- spacekit.generator.augment.logistic_noise(x)[source]
Calculates random logistic value relative to the input.
- spacekit.generator.augment.nested_image_index(tr, ts, vl=())[source]
creates a list of nested tuples for training, test, and validation Indices and Index-label Series
- spacekit.generator.augment.random_apply(func, x, p)[source]
Determine whether or not to apply a transformation according to a randomly calculated probability value.
- Parameters:
- Returns:
transformed input (or original input if no transformation is performed).
- Return type:
- spacekit.generator.augment.rotate_k(x)[source]
Rotate image array k times by 90 degrees. K is a number between 0 and 3 determined randomly when the function is called.
- Parameters:
x (numpy array) – input image array
- Returns:
randomly rotated image
- Return type:
numpy array
- spacekit.generator.augment.training_data_aug(X_train, y_train)[source]
Perform data augmentation on the training set
- Parameters:
X_train (dataframe) – training set features
y_train (dataframe) – training set target labels
- Returns:
augmented training data and target labels combined with original set (2x observations)
- Return type:
dataframes
- spacekit.generator.augment.training_img_aug(train, test, val=None, dim=3, w=128, h=128, ch=3)[source]
Perform image data augmentation on the training set
- Parameters:
train (tuple) – training set tuple of (train_index, X_train, y_train)
test (tuple) – test set tuple of (test_index, X_test, y_test)
val (tuple, optional) – val set tuple of (val_index, X_val, y_val), by default None
dim (int, optional) – dimensions (volume or number of image frames per observation), by default 3
w (int, optional) – single image width, by default 128
h (int, optional) – single image height, by default 128
ch (int, optional) – channels (rgb: 3, grayscale: 1), by default 3
- Returns:
combined image index of train, test, val; combined original and augmented training data, reshaped test and val data. If no validation data is passed in the
val
arg, then only train and test are returned.- Return type:
list of tuples of Pandas Index, numpy arrays