(self,
                            instruction=None,
                            read_mode=None,
                            verbose=0,
                            preprocess=True,
                            data_path=None,
                            new_folders=True,
                            image_column=None,
                            test_size=0.2,
                            fine_tune=None,
                            augmentation=True,
                            custom_arch=None,
                            pretrained=None,
                            epochs=10,
                            height=None,
                            width=None,
                            show_feature_map=False,
                            save_as_tfjs=None,
                            save_as_tflite=None,
                            generate_plots=None)
Calls the body of the convolutional neural network query which is located in the feedforward.py file
        :param instruction: The objective that you want to model (str).
        :param read_mode: The type of dataset (str).
        :param verbose: Printing the logging information (int).
        :param preprocess: Preprocess the data (bool).
        :param data_path: Path to the dataset (str).
        :param new_folders: Create new folders for the image during preprocessing (bool).
        :param image_column: The column in the csv file where the filepaths for the images exist (str).
        :param test_size: Ratio of dataset allotted to the testing data (float).
        :param augmentation: Perform image data augmentation (bool).
        :param epochs: Number of epochs (int).
        :param height: Height of the input image (int).
        :param width: Width of the input image (int).
        :param show_feature_map: Displays feature map graphic (bool).


        :return: an updated model and history stored in the models dictionary
Calls the body of the convolutional neural network query which is located in the feedforward.py file
        :param instruction: The objective that you want to model (str).
        :param read_mode: The type of dataset (str).
        :param verbose: Printing the logging information (int).
        :param preprocess: Preprocess the data (bool).
        :param data_path: Path to the dataset (str).
        :param new_folders: Create new folders for the image during preprocessing (bool).
        :param image_column: The column in the csv file where the filepaths for the images exist (str).
        :param test_size: Ratio of dataset allotted to the testing data (float).
        :param augmentation: Perform image data augmentation (bool).
        :param epochs: Number of epochs (int).
        :param height: Height of the input image (int).
        :param width: Width of the input image (int).
        :param show_feature_map: Displays feature map graphic (bool).
Calls the body of the convolutional neural network query which is located in the feedforward . py file : param instruction : The objective that you want to model ( str ) . : param read_mode : The type of dataset ( str ) . : param verbose : Printing the logging information ( int ) . : param preprocess : Preprocess the data ( bool ) . : param data_path : Path to the dataset ( str ) . : param new_folders : Create new folders for the image during preprocessing ( bool ) . : param image_column : The column in the csv file where the filepaths for the images exist ( str ) . : param test_size : Ratio of dataset allotted to the testing data ( float ) . : param augmentation : Perform image data augmentation ( bool ) . : param epochs : Number of epochs ( int ) . : param height : Height of the input image ( int ) . : param width : Width of the input image ( int ) . : param show_feature_map : Displays feature map graphic ( bool ) .
def convolutional_query(self,
                            instruction=None,
                            read_mode=None,
                            verbose=0,
                            preprocess=True,
                            data_path=None,
                            new_folders=True,
                            image_column=None,
                            test_size=0.2,
                            fine_tune=None,
                            augmentation=True,
                            custom_arch=None,
                            pretrained=None,
                            epochs=10,
                            height=None,
                            width=None,
                            show_feature_map=False,
                            save_as_tfjs=None,
                            save_as_tflite=None,
                            generate_plots=None):
        '''
        Calls the body of the convolutional neural network query which is located in the feedforward.py file
        :param instruction: The objective that you want to model (str).
        :param read_mode: The type of dataset (str).
        :param verbose: Printing the logging information (int).
        :param preprocess: Preprocess the data (bool).
        :param data_path: Path to the dataset (str).
        :param new_folders: Create new folders for the image during preprocessing (bool).
        :param image_column: The column in the csv file where the filepaths for the images exist (str).
        :param test_size: Ratio of dataset allotted to the testing data (float).
        :param augmentation: Perform image data augmentation (bool).
        :param epochs: Number of epochs (int).
        :param height: Height of the input image (int).
        :param width: Width of the input image (int).
        :param show_feature_map: Displays feature map graphic (bool).


        :return: an updated model and history stored in the models dictionary
        '''

        # storing values in the model dictionary
        self.models["convolutional_NN"] = convolutional(
            instruction=instruction,
            read_mode=read_mode,
            verbose=verbose,
            preprocess=preprocess,
            data_path=self.dataset,
            new_folders=new_folders,
            image_column=image_column,
            training_ratio=1 - test_size,
            fine_tune=fine_tune,
            augmentation=augmentation,
            custom_arch=custom_arch,
            pretrained=pretrained,
            epochs=epochs,
            height=height,
            width=width,
            save_as_tfjs=save_as_tfjs,
            save_as_tflite=save_as_tflite,
            generate_plots=generate_plots)

        if show_feature_map:
            model = self.models["convolutional_NN"]["model"]
            X_test = self.models["convolutional_NN"]["data"]["test"]

            # Get first image in test images and format it
            img = X_test[0][0]
            img /= 255
            successive_outputs = [layer.output for layer in model.layers[1:]]
            visualization_model = tf.keras.models.Model(inputs=model.input, outputs=successive_outputs)
            successive_feature_maps = visualization_model.predict(img)

            # Add main title to figure
            firstPlot = True

            # Include names of layers in plot
            layer_names = [layer.name for layer in model.layers]
            for layer_name, feature_map in zip(layer_names, successive_feature_maps):
                if len(feature_map.shape) == 4:

                    # Plot Feature maps for the conv / maxpool layers, not the fully-connected layers
                    n_features = feature_map.shape[-1]  # number of features in the feature map
                    height = feature_map.shape[1]  # feature map shape (1, size, size, n_features)
                    width = feature_map.shape[2]
                    display_grid = np.zeros((height, width * n_features))

                    # Format features appropriately
                    for i in range(n_features):
                        img = feature_map[0, :, :, i]
                        img -= img.mean()
                        img /= img.std()
                        img *= 64
                        img += 128
                        img = np.clip(img, 0, 255).astype('uint8')

                        # Tile each filter into a horizontal grid
                        display_grid[:, i * width: (i + 1) * width] = img

                    # Display the grid
                    scale = 20. / n_features
                    plt.figure(figsize=(scale * n_features, scale))
                    if firstPlot:
                        plt.title(f'Network Visualization\n\n{layer_name}')
                        firstPlot = False
                    else:
                        plt.title(layer_name)
                    plt.grid(False)
                    plt.imshow(display_grid, aspect='auto', cmap='viridis')
                    plt.show()

        self.latest_model = 'convolutional_NN'
        clearLog()
def convolutional_query ( self , instruction = None , read_mode = None , verbose = 0 , preprocess = True , data_path = None , new_folders = True , image_column = None , test_size = 0.2 , fine_tune = None , augmentation = True , custom_arch = None , pretrained = None , epochs = 10 , height = None , width = None , show_feature_map = False , save_as_tfjs = None , save_as_tflite = None , generate_plots = None ) : # storing values in the model dictionary self . models [ "convolutional_NN" ] = convolutional ( instruction = instruction , read_mode = read_mode , verbose = verbose , preprocess = preprocess , data_path = self . dataset , new_folders = new_folders , image_column = image_column , training_ratio = 1 - test_size , fine_tune = fine_tune , augmentation = augmentation , custom_arch = custom_arch , pretrained = pretrained , epochs = epochs , height = height , width = width , save_as_tfjs = save_as_tfjs , save_as_tflite = save_as_tflite , generate_plots = generate_plots ) if show_feature_map : model = self . models [ "convolutional_NN" ] [ "model" ] X_test = self . models [ "convolutional_NN" ] [ "data" ] [ "test" ] # Get first image in test images and format it img = X_test [ 0 ] [ 0 ] img /= 255 successive_outputs = [ layer . output for layer in model . layers [ 1 : ] ] visualization_model = tf . keras . models . Model ( inputs = model . input , outputs = successive_outputs ) successive_feature_maps = visualization_model . predict ( img ) # Add main title to figure firstPlot = True # Include names of layers in plot layer_names = [ layer . name for layer in model . layers ] for layer_name , feature_map in zip ( layer_names , successive_feature_maps ) : if len ( feature_map . shape ) == 4 : # Plot Feature maps for the conv / maxpool layers, not the fully-connected layers n_features = feature_map . shape [ - 1 ] # number of features in the feature map height = feature_map . shape [ 1 ] # feature map shape (1, size, size, n_features) width = feature_map . shape [ 2 ] display_grid = np . zeros ( ( height , width * n_features ) ) # Format features appropriately for i in range ( n_features ) : img = feature_map [ 0 , : , : , i ] img -= img . mean ( ) img /= img . std ( ) img *= 64 img += 128 img = np . clip ( img , 0 , 255 ) . astype ( 'uint8' ) # Tile each filter into a horizontal grid display_grid [ : , i * width : ( i + 1 ) * width ] = img # Display the grid scale = 20. / n_features plt . figure ( figsize = ( scale * n_features , scale ) ) if firstPlot : plt . title ( f'Network Visualization\n\n{layer_name}' ) firstPlot = False else : plt . title ( layer_name ) plt . grid ( False ) plt . imshow ( display_grid , aspect = 'auto' , cmap = 'viridis' ) plt . show ( ) self . latest_model = 'convolutional_NN' clearLog ( )