Module monk.tf_keras_1.finetune.level_9_transforms_main

Expand source code
from tf_keras_1.finetune.imports import *
from system.imports import *

from tf_keras_1.finetune.level_8_layers_main import prototype_layers


class prototype_transforms(prototype_layers):
    '''
    Main class for all transforms in expert mode

    Args:
        verbose (int): Set verbosity levels
                        0 - Print Nothing
                        1 - Print desired details
    '''


    def __init__(self, verbose=1):
        super().__init__(verbose=verbose);
        tmp = {};
        tmp["featurewise_center"] = False;
        tmp["featurewise_std_normalization"] = False;
        tmp["rotation_range"] = 0;
        tmp["width_shift_range"] = 0;
        tmp["height_shift_range"] = 0;
        tmp["shear_range"] = 0;
        tmp["zoom_range"] = 0;
        tmp["brightness_range"] = None;
        tmp["horizontal_flip"] = False;
        tmp["vertical_flip"] = False;
        tmp["mean"] = False;
        tmp["std"] = False;

        self.system_dict["local"]["transforms_train"] = tmp;
        self.system_dict["local"]["transforms_val"] = tmp;
        self.system_dict["local"]["transforms_test"] = tmp;





    ###############################################################################################################################################
    def apply_color_jitter(self, brightness=0, contrast=0, saturation=0, hue=0, train=False, val=False, test=False):
        '''
        Apply Color jittering transformations

        Args:
            brightness (float): Levels to jitter brightness.
                                        0 - min
                                        1 - max
            contrast (float): Levels to jitter contrast.
                                        0 - min
                                        1 - max
            saturation (float): Levels to jitter saturation.
                                        0 - min
                                        1 - max
            hue (float): Levels to jitter hue.
                                        0 - min
                                        1 - max
            train (bool): If True, transform applied to training data
            val (bool): If True, transform applied to validation data
            test (bool): If True, transform applied to testing/inferencing data

        Returns:
            None
        '''
        self.system_dict = transform_color_jitter(self.system_dict, brightness, contrast, saturation, hue, train, val, test);
    ###############################################################################################################################################




    ###############################################################################################################################################
    def apply_random_affine(self, degrees, translate=None, scale=None, shear=None, train=False, val=False, test=False):
        '''
        Apply random affine transformations

        Args:
            degrees (float): Max Rotation range limit for transforms
            scale (float, list): Range for randomly scaling 
            shear (float, list): Range for randomly applying sheer changes
            train (bool): If True, transform applied to training data
            val (bool): If True, transform applied to validation data
            test (bool): If True, transform applied to testing/inferencing data

        Returns:
            None
        '''
        self.system_dict = transform_random_affine(self.system_dict, degrees, translate, scale, shear, train, val, test);
    ###############################################################################################################################################



    ###############################################################################################################################################
    def apply_random_horizontal_flip(self, probability=0.5, train=False, val=False, test=False):
        '''
        Apply random horizontal flip transformations

        Args:
            probability (float): Probability of flipping the input image
            train (bool): If True, transform applied to training data
            val (bool): If True, transform applied to validation data
            test (bool): If True, transform applied to testing/inferencing data

        Returns:
            None
        '''
        self.system_dict = transform_random_horizontal_flip(self.system_dict, probability, train, val, test);
    ###############################################################################################################################################



    ###############################################################################################################################################
    def apply_random_vertical_flip(self, probability=0.5, train=False, val=False, test=False):
        '''
        Apply random vertical flip transformations

        Args:
            probability (float): Probability of flipping the input image
            train (bool): If True, transform applied to training data
            val (bool): If True, transform applied to validation data
            test (bool): If True, transform applied to testing/inferencing data

        Returns:
            None
        '''
        self.system_dict = transform_random_vertical_flip(self.system_dict, probability, train, val, test);
    ###############################################################################################################################################



    ###############################################################################################################################################
    def apply_random_rotation(self, degrees, train=False, val=False, test=False):
        '''
        Apply random rotation transformations

        Args:
            degrees (float): Max Rotation range limit for transforms
            train (bool): If True, transform applied to training data
            val (bool): If True, transform applied to validation data
            test (bool): If True, transform applied to testing/inferencing data

        Returns:
            None
        '''
        self.system_dict = transform_random_rotation(self.system_dict, degrees, train, val, test);
    ###############################################################################################################################################




    ###############################################################################################################################################
    def apply_mean_subtraction(self, mean=[123, 116, 103], train=False, val=False, test=False):
        '''
        Apply mean subtraction

        Args:
            mean (float, list): Mean value for subtraction
            train (bool): If True, transform applied to training data
            val (bool): If True, transform applied to validation data
            test (bool): If True, transform applied to testing/inferencing data

        Returns:
            None
        '''
        self.system_dict = transform_mean_subtraction(self.system_dict, mean, train, val, test);
    ###############################################################################################################################################





    ###############################################################################################################################################
    def apply_normalize(self, mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225], train=False, val=False, test=False):
        '''
        Apply mean subtraction and standard normalization

        Args:
            mean (float, list): Mean value for subtraction
            std (float, list): Normalization factor
            train (bool): If True, transform applied to training data
            val (bool): If True, transform applied to validation data
            test (bool): If True, transform applied to testing/inferencing data

        Returns:
            None
        '''
        self.system_dict = transform_normalize(self.system_dict, mean, std, train, val, test);
    ###############################################################################################################################################

Classes

class prototype_transforms (verbose=1)

Main class for all transforms in expert mode

Args

verbose : int
Set verbosity levels 0 - Print Nothing 1 - Print desired details
Expand source code
class prototype_transforms(prototype_layers):
    '''
    Main class for all transforms in expert mode

    Args:
        verbose (int): Set verbosity levels
                        0 - Print Nothing
                        1 - Print desired details
    '''


    def __init__(self, verbose=1):
        super().__init__(verbose=verbose);
        tmp = {};
        tmp["featurewise_center"] = False;
        tmp["featurewise_std_normalization"] = False;
        tmp["rotation_range"] = 0;
        tmp["width_shift_range"] = 0;
        tmp["height_shift_range"] = 0;
        tmp["shear_range"] = 0;
        tmp["zoom_range"] = 0;
        tmp["brightness_range"] = None;
        tmp["horizontal_flip"] = False;
        tmp["vertical_flip"] = False;
        tmp["mean"] = False;
        tmp["std"] = False;

        self.system_dict["local"]["transforms_train"] = tmp;
        self.system_dict["local"]["transforms_val"] = tmp;
        self.system_dict["local"]["transforms_test"] = tmp;





    ###############################################################################################################################################
    def apply_color_jitter(self, brightness=0, contrast=0, saturation=0, hue=0, train=False, val=False, test=False):
        '''
        Apply Color jittering transformations

        Args:
            brightness (float): Levels to jitter brightness.
                                        0 - min
                                        1 - max
            contrast (float): Levels to jitter contrast.
                                        0 - min
                                        1 - max
            saturation (float): Levels to jitter saturation.
                                        0 - min
                                        1 - max
            hue (float): Levels to jitter hue.
                                        0 - min
                                        1 - max
            train (bool): If True, transform applied to training data
            val (bool): If True, transform applied to validation data
            test (bool): If True, transform applied to testing/inferencing data

        Returns:
            None
        '''
        self.system_dict = transform_color_jitter(self.system_dict, brightness, contrast, saturation, hue, train, val, test);
    ###############################################################################################################################################




    ###############################################################################################################################################
    def apply_random_affine(self, degrees, translate=None, scale=None, shear=None, train=False, val=False, test=False):
        '''
        Apply random affine transformations

        Args:
            degrees (float): Max Rotation range limit for transforms
            scale (float, list): Range for randomly scaling 
            shear (float, list): Range for randomly applying sheer changes
            train (bool): If True, transform applied to training data
            val (bool): If True, transform applied to validation data
            test (bool): If True, transform applied to testing/inferencing data

        Returns:
            None
        '''
        self.system_dict = transform_random_affine(self.system_dict, degrees, translate, scale, shear, train, val, test);
    ###############################################################################################################################################



    ###############################################################################################################################################
    def apply_random_horizontal_flip(self, probability=0.5, train=False, val=False, test=False):
        '''
        Apply random horizontal flip transformations

        Args:
            probability (float): Probability of flipping the input image
            train (bool): If True, transform applied to training data
            val (bool): If True, transform applied to validation data
            test (bool): If True, transform applied to testing/inferencing data

        Returns:
            None
        '''
        self.system_dict = transform_random_horizontal_flip(self.system_dict, probability, train, val, test);
    ###############################################################################################################################################



    ###############################################################################################################################################
    def apply_random_vertical_flip(self, probability=0.5, train=False, val=False, test=False):
        '''
        Apply random vertical flip transformations

        Args:
            probability (float): Probability of flipping the input image
            train (bool): If True, transform applied to training data
            val (bool): If True, transform applied to validation data
            test (bool): If True, transform applied to testing/inferencing data

        Returns:
            None
        '''
        self.system_dict = transform_random_vertical_flip(self.system_dict, probability, train, val, test);
    ###############################################################################################################################################



    ###############################################################################################################################################
    def apply_random_rotation(self, degrees, train=False, val=False, test=False):
        '''
        Apply random rotation transformations

        Args:
            degrees (float): Max Rotation range limit for transforms
            train (bool): If True, transform applied to training data
            val (bool): If True, transform applied to validation data
            test (bool): If True, transform applied to testing/inferencing data

        Returns:
            None
        '''
        self.system_dict = transform_random_rotation(self.system_dict, degrees, train, val, test);
    ###############################################################################################################################################




    ###############################################################################################################################################
    def apply_mean_subtraction(self, mean=[123, 116, 103], train=False, val=False, test=False):
        '''
        Apply mean subtraction

        Args:
            mean (float, list): Mean value for subtraction
            train (bool): If True, transform applied to training data
            val (bool): If True, transform applied to validation data
            test (bool): If True, transform applied to testing/inferencing data

        Returns:
            None
        '''
        self.system_dict = transform_mean_subtraction(self.system_dict, mean, train, val, test);
    ###############################################################################################################################################





    ###############################################################################################################################################
    def apply_normalize(self, mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225], train=False, val=False, test=False):
        '''
        Apply mean subtraction and standard normalization

        Args:
            mean (float, list): Mean value for subtraction
            std (float, list): Normalization factor
            train (bool): If True, transform applied to training data
            val (bool): If True, transform applied to validation data
            test (bool): If True, transform applied to testing/inferencing data

        Returns:
            None
        '''
        self.system_dict = transform_normalize(self.system_dict, mean, std, train, val, test);

Ancestors

  • tf_keras_1.finetune.level_8_layers_main.prototype_layers
  • tf_keras_1.finetune.level_7_aux_main.prototype_aux
  • tf_keras_1.finetune.level_6_params_main.prototype_params
  • tf_keras_1.finetune.level_5_state_base.finetune_state
  • tf_keras_1.finetune.level_4_evaluation_base.finetune_evaluation
  • tf_keras_1.finetune.level_3_training_base.finetune_training
  • tf_keras_1.finetune.level_2_model_base.finetune_model
  • tf_keras_1.finetune.level_1_dataset_base.finetune_dataset
  • system.base_class.system

Methods

def apply_color_jitter(self, brightness=0, contrast=0, saturation=0, hue=0, train=False, val=False, test=False)

Apply Color jittering transformations

Args

brightness : float
Levels to jitter brightness. 0 - min 1 - max
contrast : float
Levels to jitter contrast. 0 - min 1 - max
saturation : float
Levels to jitter saturation. 0 - min 1 - max
hue : float
Levels to jitter hue. 0 - min 1 - max
train : bool
If True, transform applied to training data
val : bool
If True, transform applied to validation data
test : bool
If True, transform applied to testing/inferencing data

Returns

None
 
Expand source code
def apply_color_jitter(self, brightness=0, contrast=0, saturation=0, hue=0, train=False, val=False, test=False):
    '''
    Apply Color jittering transformations

    Args:
        brightness (float): Levels to jitter brightness.
                                    0 - min
                                    1 - max
        contrast (float): Levels to jitter contrast.
                                    0 - min
                                    1 - max
        saturation (float): Levels to jitter saturation.
                                    0 - min
                                    1 - max
        hue (float): Levels to jitter hue.
                                    0 - min
                                    1 - max
        train (bool): If True, transform applied to training data
        val (bool): If True, transform applied to validation data
        test (bool): If True, transform applied to testing/inferencing data

    Returns:
        None
    '''
    self.system_dict = transform_color_jitter(self.system_dict, brightness, contrast, saturation, hue, train, val, test);
def apply_mean_subtraction(self, mean=[123, 116, 103], train=False, val=False, test=False)

Apply mean subtraction

Args

mean : float, list
Mean value for subtraction
train : bool
If True, transform applied to training data
val : bool
If True, transform applied to validation data
test : bool
If True, transform applied to testing/inferencing data

Returns

None
 
Expand source code
def apply_mean_subtraction(self, mean=[123, 116, 103], train=False, val=False, test=False):
    '''
    Apply mean subtraction

    Args:
        mean (float, list): Mean value for subtraction
        train (bool): If True, transform applied to training data
        val (bool): If True, transform applied to validation data
        test (bool): If True, transform applied to testing/inferencing data

    Returns:
        None
    '''
    self.system_dict = transform_mean_subtraction(self.system_dict, mean, train, val, test);
def apply_normalize(self, mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225], train=False, val=False, test=False)

Apply mean subtraction and standard normalization

Args

mean : float, list
Mean value for subtraction
std : float, list
Normalization factor
train : bool
If True, transform applied to training data
val : bool
If True, transform applied to validation data
test : bool
If True, transform applied to testing/inferencing data

Returns

None
 
Expand source code
def apply_normalize(self, mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225], train=False, val=False, test=False):
    '''
    Apply mean subtraction and standard normalization

    Args:
        mean (float, list): Mean value for subtraction
        std (float, list): Normalization factor
        train (bool): If True, transform applied to training data
        val (bool): If True, transform applied to validation data
        test (bool): If True, transform applied to testing/inferencing data

    Returns:
        None
    '''
    self.system_dict = transform_normalize(self.system_dict, mean, std, train, val, test);
def apply_random_affine(self, degrees, translate=None, scale=None, shear=None, train=False, val=False, test=False)

Apply random affine transformations

Args

degrees : float
Max Rotation range limit for transforms
scale : float, list
Range for randomly scaling
shear : float, list
Range for randomly applying sheer changes
train : bool
If True, transform applied to training data
val : bool
If True, transform applied to validation data
test : bool
If True, transform applied to testing/inferencing data

Returns

None
 
Expand source code
def apply_random_affine(self, degrees, translate=None, scale=None, shear=None, train=False, val=False, test=False):
    '''
    Apply random affine transformations

    Args:
        degrees (float): Max Rotation range limit for transforms
        scale (float, list): Range for randomly scaling 
        shear (float, list): Range for randomly applying sheer changes
        train (bool): If True, transform applied to training data
        val (bool): If True, transform applied to validation data
        test (bool): If True, transform applied to testing/inferencing data

    Returns:
        None
    '''
    self.system_dict = transform_random_affine(self.system_dict, degrees, translate, scale, shear, train, val, test);
def apply_random_horizontal_flip(self, probability=0.5, train=False, val=False, test=False)

Apply random horizontal flip transformations

Args

probability : float
Probability of flipping the input image
train : bool
If True, transform applied to training data
val : bool
If True, transform applied to validation data
test : bool
If True, transform applied to testing/inferencing data

Returns

None
 
Expand source code
def apply_random_horizontal_flip(self, probability=0.5, train=False, val=False, test=False):
    '''
    Apply random horizontal flip transformations

    Args:
        probability (float): Probability of flipping the input image
        train (bool): If True, transform applied to training data
        val (bool): If True, transform applied to validation data
        test (bool): If True, transform applied to testing/inferencing data

    Returns:
        None
    '''
    self.system_dict = transform_random_horizontal_flip(self.system_dict, probability, train, val, test);
def apply_random_rotation(self, degrees, train=False, val=False, test=False)

Apply random rotation transformations

Args

degrees : float
Max Rotation range limit for transforms
train : bool
If True, transform applied to training data
val : bool
If True, transform applied to validation data
test : bool
If True, transform applied to testing/inferencing data

Returns

None
 
Expand source code
def apply_random_rotation(self, degrees, train=False, val=False, test=False):
    '''
    Apply random rotation transformations

    Args:
        degrees (float): Max Rotation range limit for transforms
        train (bool): If True, transform applied to training data
        val (bool): If True, transform applied to validation data
        test (bool): If True, transform applied to testing/inferencing data

    Returns:
        None
    '''
    self.system_dict = transform_random_rotation(self.system_dict, degrees, train, val, test);
def apply_random_vertical_flip(self, probability=0.5, train=False, val=False, test=False)

Apply random vertical flip transformations

Args

probability : float
Probability of flipping the input image
train : bool
If True, transform applied to training data
val : bool
If True, transform applied to validation data
test : bool
If True, transform applied to testing/inferencing data

Returns

None
 
Expand source code
def apply_random_vertical_flip(self, probability=0.5, train=False, val=False, test=False):
    '''
    Apply random vertical flip transformations

    Args:
        probability (float): Probability of flipping the input image
        train (bool): If True, transform applied to training data
        val (bool): If True, transform applied to validation data
        test (bool): If True, transform applied to testing/inferencing data

    Returns:
        None
    '''
    self.system_dict = transform_random_vertical_flip(self.system_dict, probability, train, val, test);