From 7fa649fd8fdf2758831737f4c1bccbac213bbc53 Mon Sep 17 00:00:00 2001 From: Sahil Yadav <53268444+sahilyadav27@users.noreply.github.com> Date: Fri, 2 Dec 2022 15:34:00 +0530 Subject: [PATCH 01/15] Update single_cnn.py --- ctlearn/default_models/single_cnn.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/ctlearn/default_models/single_cnn.py b/ctlearn/default_models/single_cnn.py index b4d617d2..3f7cd960 100644 --- a/ctlearn/default_models/single_cnn.py +++ b/ctlearn/default_models/single_cnn.py @@ -8,6 +8,7 @@ def single_cnn_model(data, model_params): # Load neural network model network_input = tf.keras.Input(shape=data.img_shape, name=f"images") + network_input_param = tf.keras.Input(shape=data.prm_shape, name=f"parameters") backbone_name = model_params.get("name", "CNN") + "_block" trainable_backbone = model_params.get("trainable_backbone", True) pretrained_weights = model_params.get("pretrained_weights", None) @@ -19,8 +20,10 @@ def single_cnn_model(data, model_params): model.trainable = trainable_backbone else: sys.path.append(model_params["model_directory"]) - engine_module = importlib.import_module(model_params["engine"]["module"]) - engine = getattr(engine_module, model_params["engine"]["function"]) + engine_module = importlib.import_module(model_params["engine_cnn"]["module"]) + engine_module_param = importlib.import_module(model_params["engine_prm"]["module"]) + engine = getattr(engine_module, model_params["engine_cnn"]["function"]) + engine_param = getattr(engine_module_param, model_params["engine_prm"]["function"]) # The original ResNet implementation use this padding, but we pad the images in the ImageMapper. # x = tf.pad(telescope_data, tf.constant([[3, 3], [3, 3]]), name='conv1_pad') @@ -42,11 +45,15 @@ def single_cnn_model(data, model_params): )(network_input) engine_output = engine(network_input, params=model_params, name=backbone_name) + engine_output_param = engine_param(network_input_param, params=model_params, name=backbone_name) output = tf.keras.layers.GlobalAveragePooling2D( name=backbone_name + "_global_avgpool" )(engine_output) + output_param = tf.keras.layers.Flatten()(engine_output_param) + concat = tf.keras.layers.Concatenate()([output, output_param]) + + singlecnn_model = tf.keras.Model(inputs=[network_input, network_input_param], outputs = [concat], name=backbone_name) + - singlecnn_model = tf.keras.Model(network_input, output, name=backbone_name) - - return singlecnn_model, [network_input] + return singlecnn_model, [network_input, network_input_param] From fbc2a1d66c6cd3b0c45008b948e50a5f679b23f2 Mon Sep 17 00:00:00 2001 From: Sahil Yadav <53268444+sahilyadav27@users.noreply.github.com> Date: Fri, 2 Dec 2022 15:36:54 +0530 Subject: [PATCH 02/15] Add files via upload --- .../default_config_files/singleCNN_param.yml | 493 ++++++++++++++++++ 1 file changed, 493 insertions(+) create mode 100644 ctlearn/default_config_files/singleCNN_param.yml diff --git a/ctlearn/default_config_files/singleCNN_param.yml b/ctlearn/default_config_files/singleCNN_param.yml new file mode 100644 index 00000000..246de96d --- /dev/null +++ b/ctlearn/default_config_files/singleCNN_param.yml @@ -0,0 +1,493 @@ +# Example config file containing all possible options for CTLearn, whether +# they're required or optional, their datatypes, and default arguments. +# A config file is only required for creating new models. Existing CTLearn +# benchmark models can be constructed from the command line. Please see the +# README for instructions. +# +# For an explanation of the data format and valid column names for the +# selection_string, array_info, and event_info Data config options, see +# https://github.com/cta-observatory/dl1-data-handler/wiki/CTA-ML-Data-Format +# or use ViTables http://vitables.org/ to examine the HDF5 files directly. + +# List of reconstruction tasks. For now it's recommended to you single task learning. +# Valid options: +# - 'particletype' +# - 'energy' +# - 'direction' +# These options have to be in consonance with the 'event_info' and +# 'transforms' in 'Data'. +# Requirements/recommendations: +# - 'particletype': +# event_info: +# - 'true_shower_primary_id' +# transforms: +# - name: 'ShowerPrimaryID' +# +# - 'energy': +# event_info: +# - 'true_energy' +# transforms: +# - name: 'MCEnergy' +# +# - 'direction': +# event_info: +# - 'true_energy' +# - 'true_alt' +# - 'true_az' +# transforms: +# - name: 'MCEnergy' +# - name: 'DeltaAltAz' +# +# Required list of strings. +Reco: ['energy'] + +Logging: + # Path to directory to store TensorFlow model checkpoints and summary plots. + # A timestamped copy of the configuration file will also be put here. + # Required string. + model_directory: '/home/sahil/deeplearning' + +Data: + # Either a list of data file paths, + # or a path to a file listing data file paths, one per line. + # Required list or string. + file_list: '/home/sahil/deeplearning/file_list.txt' + + # Type of examples to load. + # Optional string. Default: 'mono' + # Valid options: + # - 'mono': single images of one telescope type + # - 'stereo': stereoscopic images of events + mode: 'mono' + + # List of telescope types to load. + # Valid telescope types: + # - 'LST_LST_LSTCam': LST Telescope and Camera + # - 'LST_MAGIC_MAGICCam': MAGIC Telescopes + # - 'MST_MST_FlashCam': MST Telescope with FlashCAM Camera + # - 'MST_MST_NectarCam': MST Telescope with NectarCAM Camera + # - 'SST_SCT_SCTCam': SCT Telescope and Camera + # - 'SST_ASTRI_ASTRICam': SST-2M ASTRI Telescope and CHECH Camera + # Camera images from the following telescopes can be read, but writers + # for the data are not yet available: + # - FACT, HESS-I, HESS-II, VERITAS + # Required list of strings. + selected_telescope_types: ['LST_LST_LSTCam'] + + # Subset of telescope IDs to include of the selected telescope types. + # Optional list of integer values. + # Default: load all telescopes of the selected telescope types. + selected_telescope_ids: [1, 2, 3, 4] + + # Dict of multiplicity selection. + # Valid options: + # - 'telescope_types': int (from above) + # - 'Subarray': int (for full array multiplicity) + # Optinal dict. Not needed for MAGIC data! + #multiplicity_selection: {"LST_LST_LSTCam": 4} + parameter_list: ["hillas_intensity", "hillas_skewness", "hillas_kurtosis", "hillas_r", "hillas_phi", "hillas_length"] + # Dict of parameter selections from the DL1 file. + # The recommended way of applying quality cuts to the data. + # Only available for mono analysis at the moment. + # Optional dict. + parameter_selection: + - {col_name: "hillas_intensity", min_value: 50.0} + - {col_name: "leakage_intensity_width_2", max_value: 0.2} + + # Not the recommended way of applying quality cuts to the data. + # PyTables cut condition to apply selection cuts to events. + # Optional string. Default: don't apply any cuts + # See https://www.pytables.org/usersguide/condition_syntax.html + # for explanation of syntax. + #selection_string: '(true_energy > 1.0) & (true_h_first_int < 20000)' + + # Event selection filters to apply to each data file. + # Optional list of dictionaries with the following key/value pairs: + # - 'path': Optional string. Path to module containing filter. + # Default: path to DL1DataHandler + # - 'module': Optional string. Name of module containing filter. + # Default: 'utils' + # - 'name': Required string. Name of filter. + # - 'args': Optional dictionary. Arguments to pass to filter using + # filter(file, **args). Default: {} + # Valid filter names are those defined in DL1DataHandler or any defined + # in the specified path and module. + #event_selection: + # - + # name: 'event_intensity_filter' + # args: {i_min: 100, i_max: 316} + # - + # path: '/path/to/my/module/' + # module: 'my_filter' + # name: 'filter_fn' + # args: {'arg1': 'foo', 'arg2': 3.14} + + # Image selection filters to apply to each image (mono mode only). + # Optional list of dictionaries with the following key/value pairs: + # - 'path': Optional string. Path to module containing filter. + # Default: path to DL1DataHandler + # - 'module': Optional string. Name of module containing filter. + # Default: 'utils' + # - 'name': Required string. Name of filter. + # - 'args': Optional dictionary. Arguments to pass to filter using + # filter(file, **args). Default: {} + # Valid filter names are those defined in DL1DataHandler or any defined + # in the specified path and module. + #image_selection: + # - + # name: 'image_intensity_filter' + # args: {i_min: 10, i_max: 31.6} + # - + # path: '/path/to/my/module/' + # module: 'my_filter' + # name: 'filter_fn' + # args: {'arg1': 'foo', 'arg2': 3.14} + + # Whether to shuffle the examples. + # Optional Boolean. Default: False + shuffle: false + + # Seed for shuffling the examples. Only used if shuffle is true. + # Optional integer. Default: use default random initialization. + seed: 1234 + + # Image channels to load. + # Optional list of strings. Default: ['image'] + # Valid options are 'image', 'peak_time' 'cleaned_image' and 'clean_peak_time', or whichever columns are in + # the telescope tables of your data files. + image_channels: ['image', 'peak_time'] + + # Settings passed directly as arguments to ImageMapper. + # Optional dictionary. Default: {} + # + # The camera types supported by ImageMapper that can be used in + # the settings below are 'ASTRICam', 'CHEC', 'DigiCam', 'FACT', + # 'FlashCam', 'HESS-I', 'HESS-II', 'LSTCam', 'MAGICCam', 'NectarCam', + # 'SCTCam', and 'VERITAS'. + mapping_settings: + + # List of camera types to calculate mapping tables for. + # Optional list of camera type strings. + # Default: calculate mapping tables for all supported camera types + camera_types: ['LSTCam'] + + # Algorithm to convert image vectors to rectangular arrays + # Optional dictionary with string keys and string values. + # Default: 'oversampling' for all camera types not in the dictionary + # Valid keys are any camera types supported by ImageMapper. + # Valid mapping method options (values): + # - 'oversampling': Convert each hexagonal pixel to four square + # pixels and reweight the charge to realign to a square grid + # - 'rebinning': Interpret the intensity as a histogram and rebin + # the hexagonal histogram into a square one. + # - 'nearest_interpolation': Perform nearest neighbor + # - 'bilinear_interpolation': Draw Delaunay triangulation and + # perform bilinear interpolation + # - 'bicubic_interpolation': Draw Delaunay triangulation and + # perform bicubic interpolation + # - 'image_shifting': Shift pixels of alternate rows (hexagonal + # cameras only) + # - 'axial_addressing': Warp images by relabeling axes (hexagonal + # cameras only) + mapping_method: + 'LSTCam': 'bilinear_interpolation' + 'FlashCam': 'bilinear_interpolation' + 'NectarCam': 'bilinear_interpolation' + 'SCTCam': 'oversampling' + 'CHEC': 'oversampling' + 'MAGICCam': 'bilinear_interpolation' + + # Number of padding pixels to add around each edge of the mapped image. + # A value of 1 will increase both the image height and width by 2, etc. + # Optional dictionary with camera type string keys and integer values. + # Default: 0 for any camera type not specified + padding: + 'LSTCam': 2 + 'FlashCam': 1 + 'NectarCam': 2 + 'SCTCam': 0 + 'CHEC': 0 + 'MAGICCam': 2 + + # Shape of mapped image to return. Used only for mapping methods + # without a fixed output shape: rebinning, nearest interpolation, + # bilinear interpolation, bicubic interpolation + # Optional dictionary with camera type string keys and values that + # are lists of three integers: (, , ) + interpolation_image_shape: + 'LSTCam': [110, 110, 1] + + # Explicitly set output grid points outside the camera to 0 + # when performing bilinear and bicubic interpolation. + # Optional Boolean. Default: false + mask_interpolation: false + + # Auxiliary information to return from the Array Information table. + # Optional list of strings. Default: return no array info + # Valid options are columns in the Array_Information table. + #array_info: ['x', 'y', 'z'] + + # Auxiliary information to return from the Events table. + # Optional list of strings. Default: return no event info + # Valid options are columns in the Events table. + # These options have to be in consonance with the 'label_names' in 'Model'. + event_info: ['true_shower_primary_id', 'true_energy', 'true_alt', 'true_az'] + + # Transforms to apply to the data, in order. + # Optional list of dictionaries with the following key/value pairs: + # - 'path': Optional string. Path to module containing Transform. + # Default: path to DL1DataHandler + # - 'module': Optional string. Name of module containing Transform. + # Default: 'processor' + # - 'name': Required string. Name of Transform. + # - 'args': Optional dictionary. Arguments to pass to transform using + # Transform(**args). Default: {} + # Valid transform names are those defined in DL1DataHandler or any defined + # in the specified path and module. + transforms: + - + name: 'MCEnergy' + # - + # path: '/path/to/my/module/' + # module: 'my_transform' + # name: 'MyTransform' + # args: {'arg1': 'foo', 'arg2': 3.14} + + # Whether to validate that the shape and dtype of the processed data + # matches the example description. + # Recommended setting is True while developing the network and False + # during production. + # Optional Boolean. Default: False + validate_processor: False + +# Settings for the Keras batch generator. +Input: + + # Number of consecutive examples to combine into a batch for a single gpu. + # Optional integer. Default: 1 + batch_size_per_worker: 32 + + # Whether to concatenate the stereo images from an event to feed it + # to a monoscopic model. + # Optional boolean. Default: false + concat_telescopes: false + +# Settings for the TensorFlow model. The options in this and the +# Model Parameters section are passed to the Estimator model_fn +# and the user's model function. +Model: + + # Path to directory containing model module. + # Optional string or null. Default if missing or null is to load + # CTLearn default models directory: 'installation_path/ctlearn/ctlearn/default_models/' + #model_directory: '/my/model/path/' + + # Name of the constructed model. + # Optional string or null. + name: 'SingleCNN' + + # Required dictionary containing a module/function pair. + # Module in model directory and function in module implementing the model. + # Module and function pairs included with CTLearn: + # - {module: 'single_cnn', function: 'single_cnn_model'}: monoscopic + # model using a basic convolutional neural network (CNN) + # or residual blocks (ResNets) + # - {module: 'cnn_rnn', function: 'cnn_rnn_model'}: array model + # feeding output of a basic CNN or a ResNet for each telescope + # into a recurrent neural network (RNN) + backbone: {module: 'single_cnn', function: 'single_cnn_model'} + + # Required dict with keys 'module' and 'function' & string values. + # Module and function for the CTLearn backbone. + # Valid options: + # - {module: 'basic', function: 'conv_block'} + # - {module: 'resnet', function: 'stacked_res_blocks'} + engine_cnn: {module: 'basic', function: 'conv_block'} + engine_prm: {module: 'basic', function: 'fully_connect'} + # Optional arguments for the first Conv2D and MaxPool layer + # before the selected model. + #init_layer: {filters: 64, kernel_size: 7, strides: 1} + #init_max_pool: {size: 3, strides: 2} + + # Required dict with keys 'module' and 'function' & string values. + # Module and function for the CTLearn head. + # Valid options: + # - {module: 'head', function: 'standard_head'} + head: {module: 'head', function: 'standard_head'} + + # Required string or null. + # Path to a checkpoint file or model directory from which to load + # pretrained network weights. If null, don't load any weights. + pretrained_weights: null + + # Optional float. Default: 0.5 + # Dropout rate of dropout layers in the CNNRNN model. + dropout_rate: 0.5 + +# The options in this and the Model section are passed in a dictionary +# called "params" to the model function. +# The config option 'model_directory' above is included in params as well. +# None of these options are accessed anywhere outside the model, so +# arbitrary options may be added here. This permits custom configuration +# of user-provided models. +# Below are listed the configuration options for the CTLearn included +# models, which are only accessed if using those models. +Model Parameters: + basic: + + conv_block: + # Required list of dicts with keys 'filters', 'kernel_size' and number + # with integer values. + # If number value is not stored will be automatically set to 1 + # Filter dimension and kernel size for the CNN block + # convolutional layers. + # Number for the desired number of convolutional layers + layers: + - {filters: 32, kernel_size: 3, number: 1} + - {filters: 64, kernel_size: 3, number: 1} + - {filters: 128, kernel_size: 3, number: 1} + + # Required dictionary with keys 'size' and 'strides' and + # integer values, or null. + # Max pool size and strides. If null, don't perform any pooling. + max_pool: {size: 2, strides: 2} + + # Required integer or null. + # Number of output filters of a final 1x1 convolutional layer. + # If null, don't include this bottleneck layer. + bottleneck: null + + # Optional Boolean. Default: false + # Whether to include a batch normalization layer after each + # convolutional layer. Exercise caution when using with + # array-level models. + batchnorm: false + + fully_connect: + # Required list of integers. + # Number of units for each fully-connected head dense layer. + layers: [1024, 512, 256, 128] + + # Optional Boolean. Default: false + # Whether to include a batch normalization layer after each + # dense layer. + batchnorm: false + + conv_head: + # Required list of dicts with keys 'filters' and 'kernel_size' + # with integer values. + # Filter dimension and kernel size for the convolutional + # network head layers. + layers: + - {filters: 64, kernel_size: 3} + - {filters: 128, kernel_size: 3} + - {filters: 256, kernel_size: 3} + + # Optional Boolean. Default: true + # Whether to perform average pooling over spatial dimensions + # of the convolutional output before calculating final output. + final_avg_pool: true + + # Optional Boolean. Default: false + # Whether to include a batch normalization layer after each + # convolutional layer. + batchnorm: false + + # Optional float. Default: 0.99 + # Decay parameter for batch normalization layers. + batchnorm_decay: 0.99 + + resnet: + stacked_res_blocks: + # Optional string. Default: 'bottleneck' + # Type of the residual block. + # Valid options: + # - 'basic' + # - 'bottleneck' + residual_block: 'bottleneck' + + # Required list of dicts with keys 'filters' and 'blocks' + # with integer values. + # Filter dimension and number of blocks for the ResNet + # architecture. + # Typical ResNet architectures: + # Thin-ResNet + #- {filters: 48, blocks: 2} + #- {filters: 96, blocks: 3} + #- {filters: 128, blocks: 3} + #- {filters: 256, blocks: 3} + # ResNet50 + #- {filters: 64, blocks: 3} + #- {filters: 128, blocks: 4} + #- {filters: 256, blocks: 6} + #- {filters: 512, blocks: 3} + architecture: + - {filters: 48, blocks: 2} + - {filters: 96, blocks: 3} + - {filters: 128, blocks: 3} + - {filters: 256, blocks: 3} + + # Dictionary of tasks where the values contain the fully connected layers + # head of each reconstruction task. The final loss is calculated with a weighted sum + # over the individual losses. Currently the weights are constanst values. + # For the classification task, the class names are passed into the dict + # in order of class label (0 to n-1). + standard_head: + particletype: {class_names: ['proton', 'gamma'], fc_head: [512, 256, 2], weight: 1.0} + energy: {fc_head: [512, 256, 1], weight: 1.0} + direction: {fc_head: [512, 256, 2], weight: 1.0} + + # Optional dict of attention mechanisms. + # Valid options: + # Dual attention (Spatial and channel squeeze-and-excitation attention) + # - {mechanism: 'Squeeze-and-Excitation', ratio: 16} + # Channel Squeeze-and-excitation attention + # - {mechanism: 'Channel-Squeeze-and-Excitation', ratio: 4} + # Spatial squeeze-and-excitatiom attention + # - {mechanism: 'Spatial-Squeeze-and-Excitation'} + # References: + # - [Squeeze and Excitation Networks](https://arxiv.org/abs/1709.01507) + # - [Concurrent Spatial and Channel Squeeze & Excitation in Fully Convolutional Networks](https://arxiv.org/abs/1803.02579) + attention: {mechanism: 'Squeeze-and-Excitation', ratio: 16} + +Training: + + # Optional float. Default: 0.1 + # Randomly chosen fraction of data to set aside for validation. + validation_split: 0.1 + + # Required number of epochs on which to train. + num_epochs: 20 + + # Required string. + # Valid options: ['Adadelta', 'Adam', 'RMSProp', 'SGD'] + # Optimizer function for training. + optimizer: 'Adam' + + # Optional float. Required if optimizer is 'Adam', ignored otherwise. + # Epsilon parameter for the Adam optimizer. + adam_epsilon: 1.0e-8 + + # Required integer. + # Base learning rate before scaling or annealing. + base_learning_rate: 0.001 + + # Optional integer and floats. + # Reducing the learning rate after the network stops learning. + lr_reducing_patience: 5 + lr_reducing_factor: 0.5 + lr_reducing_mindelta: 0.01 + lr_reducing_minlr: 0.00001 + +Prediction: + + # Required string if running in predict mode. + # Name of the file to save predictions. + prediction_file: ./ctlearn_prediction.h5 + + # A dict of either a list of data file paths, + # or a path to a file listing data file paths, one per line. + # Required dict of list or string if running in predict mode. + prediction_file_lists: + prediction_file_list1.h5: /tmp/dataset/prediction_file_list1.txt + prediction_file_list2.h5: /tmp/dataset/prediction_file_list2.txt From bd92e9bebfc71a9253b322ab8cf3cf723ce0cbc3 Mon Sep 17 00:00:00 2001 From: Sahil Yadav <53268444+sahilyadav27@users.noreply.github.com> Date: Fri, 2 Dec 2022 16:25:17 +0530 Subject: [PATCH 03/15] Update single_cnn.py --- ctlearn/default_models/single_cnn.py | 30 ++++++++++++++-------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/ctlearn/default_models/single_cnn.py b/ctlearn/default_models/single_cnn.py index 3f7cd960..0edbb69b 100644 --- a/ctlearn/default_models/single_cnn.py +++ b/ctlearn/default_models/single_cnn.py @@ -7,7 +7,7 @@ def single_cnn_model(data, model_params): # Load neural network model - network_input = tf.keras.Input(shape=data.img_shape, name=f"images") + network_input_img = tf.keras.Input(shape=data.img_shape, name=f"images") network_input_param = tf.keras.Input(shape=data.prm_shape, name=f"parameters") backbone_name = model_params.get("name", "CNN") + "_block" trainable_backbone = model_params.get("trainable_backbone", True) @@ -20,40 +20,40 @@ def single_cnn_model(data, model_params): model.trainable = trainable_backbone else: sys.path.append(model_params["model_directory"]) - engine_module = importlib.import_module(model_params["engine_cnn"]["module"]) - engine_module_param = importlib.import_module(model_params["engine_prm"]["module"]) - engine = getattr(engine_module, model_params["engine_cnn"]["function"]) - engine_param = getattr(engine_module_param, model_params["engine_prm"]["function"]) + engine_cnn_module_img = importlib.import_module(model_params["engine_cnn"]["module"]) + engine_mlp_module_param = importlib.import_module(model_params["engine_prm"]["module"]) + engine_img = getattr(engine_cnn_module_img, model_params["engine_cnn"]["function"]) + engine_param = getattr(engine_mlp_module_param, model_params["engine_prm"]["function"]) # The original ResNet implementation use this padding, but we pad the images in the ImageMapper. # x = tf.pad(telescope_data, tf.constant([[3, 3], [3, 3]]), name='conv1_pad') init_layer = model_params.get("init_layer", False) if init_layer: - network_input = tf.keras.layers.Conv2D( + network_input_img = tf.keras.layers.Conv2D( filters=init_layer["filters"], kernel_size=init_layer["kernel_size"], strides=init_layer["strides"], name=backbone_name + "_conv1_conv", - )(network_input) + )(network_input_img) # x = tf.pad(x, tf.constant([[1, 1], [1, 1]]), name='pool1_pad') init_max_pool = model_params.get("init_max_pool", False) if init_max_pool: - network_input = tf.keras.layers.MaxPool2D( + network_input_img = tf.keras.layers.MaxPool2D( pool_size=init_max_pool["size"], strides=init_max_pool["strides"], name=backbone_name + "_pool1_pool", - )(network_input) + )(network_input_img) - engine_output = engine(network_input, params=model_params, name=backbone_name) + engine_output_img = engine_img(network_input_img, params=model_params, name=backbone_name) engine_output_param = engine_param(network_input_param, params=model_params, name=backbone_name) - output = tf.keras.layers.GlobalAveragePooling2D( + output_img = tf.keras.layers.GlobalAveragePooling2D( name=backbone_name + "_global_avgpool" - )(engine_output) + )(engine_output_img) output_param = tf.keras.layers.Flatten()(engine_output_param) - concat = tf.keras.layers.Concatenate()([output, output_param]) + concat = tf.keras.layers.Concatenate()([output_img, output_param]) - singlecnn_model = tf.keras.Model(inputs=[network_input, network_input_param], outputs = [concat], name=backbone_name) + singlecnn_model = tf.keras.Model(inputs=[network_input_img, network_input_param], outputs = [concat], name=backbone_name) - return singlecnn_model, [network_input, network_input_param] + return singlecnn_model, [network_input_img, network_input_param] From 893c2a39907ea3a84c0275aed69fb174c281e2a2 Mon Sep 17 00:00:00 2001 From: Sahil Yadav <53268444+sahilyadav27@users.noreply.github.com> Date: Fri, 2 Dec 2022 16:30:35 +0530 Subject: [PATCH 04/15] Update single_cnn.py --- ctlearn/default_models/single_cnn.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/ctlearn/default_models/single_cnn.py b/ctlearn/default_models/single_cnn.py index 0edbb69b..be852b2c 100644 --- a/ctlearn/default_models/single_cnn.py +++ b/ctlearn/default_models/single_cnn.py @@ -22,8 +22,8 @@ def single_cnn_model(data, model_params): sys.path.append(model_params["model_directory"]) engine_cnn_module_img = importlib.import_module(model_params["engine_cnn"]["module"]) engine_mlp_module_param = importlib.import_module(model_params["engine_prm"]["module"]) - engine_img = getattr(engine_cnn_module_img, model_params["engine_cnn"]["function"]) - engine_param = getattr(engine_mlp_module_param, model_params["engine_prm"]["function"]) + engine_cnn = getattr(engine_cnn_module_img, model_params["engine_cnn"]["function"]) + engine_mlp = getattr(engine_mlp_module_param, model_params["engine_prm"]["function"]) # The original ResNet implementation use this padding, but we pad the images in the ImageMapper. # x = tf.pad(telescope_data, tf.constant([[3, 3], [3, 3]]), name='conv1_pad') @@ -44,14 +44,14 @@ def single_cnn_model(data, model_params): name=backbone_name + "_pool1_pool", )(network_input_img) - engine_output_img = engine_img(network_input_img, params=model_params, name=backbone_name) - engine_output_param = engine_param(network_input_param, params=model_params, name=backbone_name) + engine_output_cnn = engine_cnn(network_input_img, params=model_params, name=backbone_name) + engine_output_mlp = engine_mlp(network_input_param, params=model_params, name=backbone_name) - output_img = tf.keras.layers.GlobalAveragePooling2D( + output_cnn = tf.keras.layers.GlobalAveragePooling2D( name=backbone_name + "_global_avgpool" - )(engine_output_img) - output_param = tf.keras.layers.Flatten()(engine_output_param) - concat = tf.keras.layers.Concatenate()([output_img, output_param]) + )(engine_output_cnn) + output_mlp = tf.keras.layers.Flatten()(engine_output_mlp) + concat = tf.keras.layers.Concatenate()([output_cnn, output_mlp]) singlecnn_model = tf.keras.Model(inputs=[network_input_img, network_input_param], outputs = [concat], name=backbone_name) From edd8b23157700b64a4f34f7fb9f2f39051c27ab7 Mon Sep 17 00:00:00 2001 From: Sahil Yadav <53268444+sahilyadav27@users.noreply.github.com> Date: Fri, 2 Dec 2022 17:15:18 +0530 Subject: [PATCH 05/15] Update single_cnn.py --- ctlearn/default_models/single_cnn.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ctlearn/default_models/single_cnn.py b/ctlearn/default_models/single_cnn.py index be852b2c..c09d34e6 100644 --- a/ctlearn/default_models/single_cnn.py +++ b/ctlearn/default_models/single_cnn.py @@ -20,10 +20,10 @@ def single_cnn_model(data, model_params): model.trainable = trainable_backbone else: sys.path.append(model_params["model_directory"]) - engine_cnn_module_img = importlib.import_module(model_params["engine_cnn"]["module"]) - engine_mlp_module_param = importlib.import_module(model_params["engine_prm"]["module"]) - engine_cnn = getattr(engine_cnn_module_img, model_params["engine_cnn"]["function"]) - engine_mlp = getattr(engine_mlp_module_param, model_params["engine_prm"]["function"]) + engine_cnn_module = importlib.import_module(model_params["engine_cnn"]["module"]) + engine_mlp_module = importlib.import_module(model_params["engine_mlp"]["module"]) + engine_cnn = getattr(engine_cnn_module, model_params["engine_cnn"]["function"]) + engine_mlp = getattr(engine_mlp_module, model_params["engine_mlp"]["function"]) # The original ResNet implementation use this padding, but we pad the images in the ImageMapper. # x = tf.pad(telescope_data, tf.constant([[3, 3], [3, 3]]), name='conv1_pad') From fe6d9d6fc2248e41bdf62e9a0d853af544d8bf1b Mon Sep 17 00:00:00 2001 From: Sahil Yadav <53268444+sahilyadav27@users.noreply.github.com> Date: Fri, 2 Dec 2022 17:16:02 +0530 Subject: [PATCH 06/15] Update singleCNN_param.yml --- ctlearn/default_config_files/singleCNN_param.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ctlearn/default_config_files/singleCNN_param.yml b/ctlearn/default_config_files/singleCNN_param.yml index 246de96d..e42884db 100644 --- a/ctlearn/default_config_files/singleCNN_param.yml +++ b/ctlearn/default_config_files/singleCNN_param.yml @@ -45,13 +45,13 @@ Logging: # Path to directory to store TensorFlow model checkpoints and summary plots. # A timestamped copy of the configuration file will also be put here. # Required string. - model_directory: '/home/sahil/deeplearning' + #model_directory: '/home/sahil/deeplearning' Data: # Either a list of data file paths, # or a path to a file listing data file paths, one per line. # Required list or string. - file_list: '/home/sahil/deeplearning/file_list.txt' + #file_list: '/home/sahil/deeplearning/file_list.txt' # Type of examples to load. # Optional string. Default: 'mono' @@ -303,7 +303,7 @@ Model: # - {module: 'basic', function: 'conv_block'} # - {module: 'resnet', function: 'stacked_res_blocks'} engine_cnn: {module: 'basic', function: 'conv_block'} - engine_prm: {module: 'basic', function: 'fully_connect'} + engine_mlp: {module: 'basic', function: 'fully_connect'} # Optional arguments for the first Conv2D and MaxPool layer # before the selected model. #init_layer: {filters: 64, kernel_size: 7, strides: 1} From cfceeaf25150c1d7e94b39b6980eb906131fad21 Mon Sep 17 00:00:00 2001 From: Sahil Yadav <53268444+sahilyadav27@users.noreply.github.com> Date: Tue, 6 Dec 2022 22:34:48 +0530 Subject: [PATCH 07/15] Update single_cnn.py --- ctlearn/default_models/single_cnn.py | 29 +++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/ctlearn/default_models/single_cnn.py b/ctlearn/default_models/single_cnn.py index c09d34e6..f54c2861 100644 --- a/ctlearn/default_models/single_cnn.py +++ b/ctlearn/default_models/single_cnn.py @@ -8,7 +8,10 @@ def single_cnn_model(data, model_params): # Load neural network model network_input_img = tf.keras.Input(shape=data.img_shape, name=f"images") - network_input_param = tf.keras.Input(shape=data.prm_shape, name=f"parameters") + flag_prm = 0 + if data.prm_shape != None: + flag_prm = 1 + network_input_param = tf.keras.Input(shape=data.prm_shape, name=f"parameters") backbone_name = model_params.get("name", "CNN") + "_block" trainable_backbone = model_params.get("trainable_backbone", True) pretrained_weights = model_params.get("pretrained_weights", None) @@ -21,10 +24,12 @@ def single_cnn_model(data, model_params): else: sys.path.append(model_params["model_directory"]) engine_cnn_module = importlib.import_module(model_params["engine_cnn"]["module"]) - engine_mlp_module = importlib.import_module(model_params["engine_mlp"]["module"]) engine_cnn = getattr(engine_cnn_module, model_params["engine_cnn"]["function"]) - engine_mlp = getattr(engine_mlp_module, model_params["engine_mlp"]["function"]) - + if flag_prm == 1: + engine_mlp_module = importlib.import_module(model_params["engine_mlp"]["module"]) + engine_mlp = getattr(engine_mlp_module, model_params["engine_mlp"]["function"]) + engine_output_mlp = engine_mlp(network_input_param, params=model_params, name=backbone_name) + output_mlp = tf.keras.layers.Flatten()(engine_output_mlp) # The original ResNet implementation use this padding, but we pad the images in the ImageMapper. # x = tf.pad(telescope_data, tf.constant([[3, 3], [3, 3]]), name='conv1_pad') init_layer = model_params.get("init_layer", False) @@ -45,15 +50,13 @@ def single_cnn_model(data, model_params): )(network_input_img) engine_output_cnn = engine_cnn(network_input_img, params=model_params, name=backbone_name) - engine_output_mlp = engine_mlp(network_input_param, params=model_params, name=backbone_name) - output_cnn = tf.keras.layers.GlobalAveragePooling2D( name=backbone_name + "_global_avgpool" )(engine_output_cnn) - output_mlp = tf.keras.layers.Flatten()(engine_output_mlp) - concat = tf.keras.layers.Concatenate()([output_cnn, output_mlp]) - - singlecnn_model = tf.keras.Model(inputs=[network_input_img, network_input_param], outputs = [concat], name=backbone_name) - - - return singlecnn_model, [network_input_img, network_input_param] + if flag_prm == 1: + concat = tf.keras.layers.Concatenate()([output_cnn, output_mlp]) + singlecnn_model = tf.keras.Model(inputs=[network_input_img, network_input_param], outputs = [concat], name=backbone_name) + return singlecnn_model, [network_input_img, network_input_param] + else: + singlecnn_model = tf.keras.Model(network_input_img, output_cnn, name=backbone_name) + return singlecnn_model, [network_input_img] From f8194caf0e337cef9e694175ef06fa71b54daf45 Mon Sep 17 00:00:00 2001 From: Sahil Yadav <53268444+sahilyadav27@users.noreply.github.com> Date: Sat, 10 Dec 2022 14:57:00 +0530 Subject: [PATCH 08/15] Update single_cnn.py --- ctlearn/default_models/single_cnn.py | 89 ++++++++++++++++------------ 1 file changed, 50 insertions(+), 39 deletions(-) diff --git a/ctlearn/default_models/single_cnn.py b/ctlearn/default_models/single_cnn.py index f54c2861..62c5eb41 100644 --- a/ctlearn/default_models/single_cnn.py +++ b/ctlearn/default_models/single_cnn.py @@ -7,11 +7,23 @@ def single_cnn_model(data, model_params): # Load neural network model - network_input_img = tf.keras.Input(shape=data.img_shape, name=f"images") - flag_prm = 0 - if data.prm_shape != None: - flag_prm = 1 - network_input_param = tf.keras.Input(shape=data.prm_shape, name=f"parameters") + network_input, network_output = [], [] + if data.img_shape != None: + network_input_img = tf.keras.Input(shape=data.img_shape, name=f"images") + network_input.append(network_input_img) + backbone_name = model_params.get("name", "CNN") + "_block" + trainable_backbone = model_params.get("trainable_backbone", True) + pretrained_weights = model_params.get("pretrained_weights", None) + if pretrained_weights: + loaded_model = tf.keras.models.load_model(pretrained_weights) + for layer in loaded_model.layers: + if layer.name.endswith("_block"): + model = loaded_model.get_layer(layer.name) + model.trainable = trainable_backbone + + if data.prm_shape != None and data.mode == "train": + network_input_prm = tf.keras.Input(shape=data.prm_shape, name=f"parameters") + network_input.append(network_input_prm) backbone_name = model_params.get("name", "CNN") + "_block" trainable_backbone = model_params.get("trainable_backbone", True) pretrained_weights = model_params.get("pretrained_weights", None) @@ -23,40 +35,39 @@ def single_cnn_model(data, model_params): model.trainable = trainable_backbone else: sys.path.append(model_params["model_directory"]) - engine_cnn_module = importlib.import_module(model_params["engine_cnn"]["module"]) - engine_cnn = getattr(engine_cnn_module, model_params["engine_cnn"]["function"]) - if flag_prm == 1: + if data.img_shape != None: + engine_cnn_module = importlib.import_module(model_params["engine_cnn"]["module"]) + engine_cnn = getattr(engine_cnn_module, model_params["engine_cnn"]["function"]) + # The original ResNet implementation use this padding, but we pad the images in the ImageMapper. + # x = tf.pad(telescope_data, tf.constant([[3, 3], [3, 3]]), name='conv1_pad') + init_layer = model_params.get("init_layer", False) + if init_layer: + network_input_img = tf.keras.layers.Conv2D( + filters=init_layer["filters"], + kernel_size=init_layer["kernel_size"], + strides=init_layer["strides"], + name=backbone_name + "_conv1_conv", + )(network_input_img) + # x = tf.pad(x, tf.constant([[1, 1], [1, 1]]), name='pool1_pad') + init_max_pool = model_params.get("init_max_pool", False) + if init_max_pool: + network_input_img = tf.keras.layers.MaxPool2D( + pool_size=init_max_pool["size"], + strides=init_max_pool["strides"], + name=backbone_name + "_pool1_pool", + )(network_input_img) + engine_output_cnn = engine_cnn(network_input_img, params=model_params, name=backbone_name) + network_output = output_cnn = tf.keras.layers.GlobalAveragePooling2D( + name=backbone_name + "_global_avgpool" + )(engine_output_cnn) + if data.prm_shape != None and data.mode == "train": engine_mlp_module = importlib.import_module(model_params["engine_mlp"]["module"]) engine_mlp = getattr(engine_mlp_module, model_params["engine_mlp"]["function"]) - engine_output_mlp = engine_mlp(network_input_param, params=model_params, name=backbone_name) - output_mlp = tf.keras.layers.Flatten()(engine_output_mlp) - # The original ResNet implementation use this padding, but we pad the images in the ImageMapper. - # x = tf.pad(telescope_data, tf.constant([[3, 3], [3, 3]]), name='conv1_pad') - init_layer = model_params.get("init_layer", False) - if init_layer: - network_input_img = tf.keras.layers.Conv2D( - filters=init_layer["filters"], - kernel_size=init_layer["kernel_size"], - strides=init_layer["strides"], - name=backbone_name + "_conv1_conv", - )(network_input_img) - # x = tf.pad(x, tf.constant([[1, 1], [1, 1]]), name='pool1_pad') - init_max_pool = model_params.get("init_max_pool", False) - if init_max_pool: - network_input_img = tf.keras.layers.MaxPool2D( - pool_size=init_max_pool["size"], - strides=init_max_pool["strides"], - name=backbone_name + "_pool1_pool", - )(network_input_img) + engine_output_mlp = engine_mlp(network_input_prm, params=model_params, name=backbone_name) + network_output = output_mlp = tf.keras.layers.Flatten()(engine_output_mlp) + + if data.img_shape != None and data.prm_shape != None and data.mode == "train": + network_output = tf.keras.layers.Concatenate()([output_cnn, output_mlp]) - engine_output_cnn = engine_cnn(network_input_img, params=model_params, name=backbone_name) - output_cnn = tf.keras.layers.GlobalAveragePooling2D( - name=backbone_name + "_global_avgpool" - )(engine_output_cnn) - if flag_prm == 1: - concat = tf.keras.layers.Concatenate()([output_cnn, output_mlp]) - singlecnn_model = tf.keras.Model(inputs=[network_input_img, network_input_param], outputs = [concat], name=backbone_name) - return singlecnn_model, [network_input_img, network_input_param] - else: - singlecnn_model = tf.keras.Model(network_input_img, output_cnn, name=backbone_name) - return singlecnn_model, [network_input_img] + singlecnn_model = tf.keras.Model(network_input, network_output, name=backbone_name) + return singlecnn_model, network_input From 60a4fb9e5cefd46506b643b0aa2ca8bc50180232 Mon Sep 17 00:00:00 2001 From: Sahil Yadav <53268444+sahilyadav27@users.noreply.github.com> Date: Sat, 10 Dec 2022 15:35:38 +0530 Subject: [PATCH 09/15] Update single_cnn.py --- ctlearn/default_models/single_cnn.py | 41 ++++++++++------------------ 1 file changed, 14 insertions(+), 27 deletions(-) diff --git a/ctlearn/default_models/single_cnn.py b/ctlearn/default_models/single_cnn.py index 62c5eb41..d2ad9ada 100644 --- a/ctlearn/default_models/single_cnn.py +++ b/ctlearn/default_models/single_cnn.py @@ -3,7 +3,6 @@ import tensorflow as tf - def single_cnn_model(data, model_params): # Load neural network model @@ -20,22 +19,8 @@ def single_cnn_model(data, model_params): if layer.name.endswith("_block"): model = loaded_model.get_layer(layer.name) model.trainable = trainable_backbone - - if data.prm_shape != None and data.mode == "train": - network_input_prm = tf.keras.Input(shape=data.prm_shape, name=f"parameters") - network_input.append(network_input_prm) - backbone_name = model_params.get("name", "CNN") + "_block" - trainable_backbone = model_params.get("trainable_backbone", True) - pretrained_weights = model_params.get("pretrained_weights", None) - if pretrained_weights: - loaded_model = tf.keras.models.load_model(pretrained_weights) - for layer in loaded_model.layers: - if layer.name.endswith("_block"): - model = loaded_model.get_layer(layer.name) - model.trainable = trainable_backbone - else: - sys.path.append(model_params["model_directory"]) - if data.img_shape != None: + else: + sys.path.append(model_params["model_directory"]) engine_cnn_module = importlib.import_module(model_params["engine_cnn"]["module"]) engine_cnn = getattr(engine_cnn_module, model_params["engine_cnn"]["function"]) # The original ResNet implementation use this padding, but we pad the images in the ImageMapper. @@ -60,14 +45,16 @@ def single_cnn_model(data, model_params): network_output = output_cnn = tf.keras.layers.GlobalAveragePooling2D( name=backbone_name + "_global_avgpool" )(engine_output_cnn) - if data.prm_shape != None and data.mode == "train": - engine_mlp_module = importlib.import_module(model_params["engine_mlp"]["module"]) - engine_mlp = getattr(engine_mlp_module, model_params["engine_mlp"]["function"]) - engine_output_mlp = engine_mlp(network_input_prm, params=model_params, name=backbone_name) - network_output = output_mlp = tf.keras.layers.Flatten()(engine_output_mlp) - - if data.img_shape != None and data.prm_shape != None and data.mode == "train": - network_output = tf.keras.layers.Concatenate()([output_cnn, output_mlp]) - singlecnn_model = tf.keras.Model(network_input, network_output, name=backbone_name) - return singlecnn_model, network_input + if data.prm_shape != None and data.mode == "train": + network_input_prm = tf.keras.Input(shape=data.prm_shape, name=f"parameters") + network_input.append(network_input_prm) + engine_mlp_module = importlib.import_module(model_params["engine_mlp"]["module"]) + engine_mlp = getattr(engine_mlp_module, model_params["engine_mlp"]["function"]) + engine_output_mlp = engine_mlp(network_input_prm, params=model_params, name=backbone_name) + network_output = output_mlp = tf.keras.layers.Flatten()(engine_output_mlp) + if data.img_shape != None: + network_output = tf.keras.layers.Concatenate()([output_cnn, output_mlp]) + + singlecnn_model = tf.keras.Model(network_input, network_output, name=backbone_name) + return singlecnn_model, network_input From 1bbae3ff59a48d6d9371b1c82359285360cb056a Mon Sep 17 00:00:00 2001 From: Sahil Yadav <53268444+sahilyadav27@users.noreply.github.com> Date: Sat, 10 Dec 2022 18:06:49 +0530 Subject: [PATCH 10/15] Update single_cnn.py --- ctlearn/default_models/single_cnn.py | 50 +++++++++++++++------------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/ctlearn/default_models/single_cnn.py b/ctlearn/default_models/single_cnn.py index d2ad9ada..49f2784f 100644 --- a/ctlearn/default_models/single_cnn.py +++ b/ctlearn/default_models/single_cnn.py @@ -3,24 +3,30 @@ import tensorflow as tf -def single_cnn_model(data, model_params): +def single_nn_model(data, model_params): # Load neural network model network_input, network_output = [], [] if data.img_shape != None: network_input_img = tf.keras.Input(shape=data.img_shape, name=f"images") network_input.append(network_input_img) - backbone_name = model_params.get("name", "CNN") + "_block" - trainable_backbone = model_params.get("trainable_backbone", True) - pretrained_weights = model_params.get("pretrained_weights", None) - if pretrained_weights: - loaded_model = tf.keras.models.load_model(pretrained_weights) - for layer in loaded_model.layers: - if layer.name.endswith("_block"): - model = loaded_model.get_layer(layer.name) - model.trainable = trainable_backbone - else: - sys.path.append(model_params["model_directory"]) + + if data.prm_shape != None and data.mode == "train": + network_input_prm = tf.keras.Input(shape=data.prm_shape, name=f"parameters") + network_input.append(network_input_prm) + + backbone_name = model_params.get("name", "SingleNN") + "_backbone" + trainable_backbone = model_params.get("trainable_backbone", True) + pretrained_weights = model_params.get("pretrained_weights", None) + if pretrained_weights: + loaded_model = tf.keras.models.load_model(pretrained_weights) + for layer in loaded_model.layers: + if "_backbone" in layer.name: + singlenn_model = loaded_model.get_layer(layer.name) + singlenn_model.trainable = trainable_backbone + else: + sys.path.append(model_params["model_directory"]) + if data.img_shape != None: engine_cnn_module = importlib.import_module(model_params["engine_cnn"]["module"]) engine_cnn = getattr(engine_cnn_module, model_params["engine_cnn"]["function"]) # The original ResNet implementation use this padding, but we pad the images in the ImageMapper. @@ -46,15 +52,13 @@ def single_cnn_model(data, model_params): name=backbone_name + "_global_avgpool" )(engine_output_cnn) - if data.prm_shape != None and data.mode == "train": - network_input_prm = tf.keras.Input(shape=data.prm_shape, name=f"parameters") - network_input.append(network_input_prm) - engine_mlp_module = importlib.import_module(model_params["engine_mlp"]["module"]) - engine_mlp = getattr(engine_mlp_module, model_params["engine_mlp"]["function"]) - engine_output_mlp = engine_mlp(network_input_prm, params=model_params, name=backbone_name) - network_output = output_mlp = tf.keras.layers.Flatten()(engine_output_mlp) - if data.img_shape != None: - network_output = tf.keras.layers.Concatenate()([output_cnn, output_mlp]) + if data.prm_shape != None and data.mode == "train": + engine_mlp_module = importlib.import_module(model_params["engine_mlp"]["module"]) + engine_mlp = getattr(engine_mlp_module, model_params["engine_mlp"]["function"]) + engine_output_mlp = engine_mlp(network_input_prm, params=model_params, name=backbone_name) + network_output = output_mlp = tf.keras.layers.Flatten()(engine_output_mlp) + if data.img_shape != None: + network_output = tf.keras.layers.Concatenate()([output_cnn, output_mlp]) - singlecnn_model = tf.keras.Model(network_input, network_output, name=backbone_name) - return singlecnn_model, network_input + singlenn_model = tf.keras.Model(network_input, network_output, name=backbone_name) + return singlenn_model, network_input From 5a6510cf6e8075e11ce0735351e5f4b0fa5776c6 Mon Sep 17 00:00:00 2001 From: Sahil Yadav <53268444+sahilyadav27@users.noreply.github.com> Date: Sat, 10 Dec 2022 18:07:30 +0530 Subject: [PATCH 11/15] Update cnn_rnn.py --- ctlearn/default_models/cnn_rnn.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ctlearn/default_models/cnn_rnn.py b/ctlearn/default_models/cnn_rnn.py index 2c60c39b..dffeec9a 100644 --- a/ctlearn/default_models/cnn_rnn.py +++ b/ctlearn/default_models/cnn_rnn.py @@ -27,7 +27,7 @@ def cnn_rnn_model(data, model_params): if pretrained_weights: loaded_model = tf.keras.models.load_model(pretrained_weights) for layer in loaded_model.layers: - if layer.name.endswith("_block"): + if layer.name.endswith("_backbone"): model = loaded_model.get_layer(layer.name) model.trainable = trainable_backbone else: From 66d4e94e5fe517cfd8189bc638da714ad113a259 Mon Sep 17 00:00:00 2001 From: Sahil Yadav <53268444+sahilyadav27@users.noreply.github.com> Date: Sat, 10 Dec 2022 18:41:23 +0530 Subject: [PATCH 12/15] Add files via upload --- ctlearn/default_models/single_nn.py | 79 +++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 ctlearn/default_models/single_nn.py diff --git a/ctlearn/default_models/single_nn.py b/ctlearn/default_models/single_nn.py new file mode 100644 index 00000000..b28cd1c5 --- /dev/null +++ b/ctlearn/default_models/single_nn.py @@ -0,0 +1,79 @@ +import importlib +import sys + +import tensorflow as tf + + +def single_cnn_model(data, model_params): + + # Load neural network model + network_input, network_output = [], [] + if data.img_shape != None: + network_input_img = tf.keras.Input(shape=data.img_shape, name=f"images") + network_input.append(network_input_img) + + if data.prm_shape != None and data.mode == "train": + network_input_prm = tf.keras.Input(shape=data.prm_shape, name=f"parameters") + network_input.append(network_input_prm) + + backbone_name = model_params.get("name", "SingleNN") + "_backbone" + trainable_backbone = model_params.get("trainable_backbone", True) + pretrained_weights = model_params.get("pretrained_weights", None) + if pretrained_weights: + loaded_model = tf.keras.models.load_model(pretrained_weights) + for layer in loaded_model.layers: + if "_backbone" in layer.name: + singlecnn_model = loaded_model.get_layer(layer.name) + singlecnn_model.trainable = trainable_backbone + else: + sys.path.append(model_params["model_directory"]) + if data.img_shape != None: + engine_cnn_module = importlib.import_module( + model_params["engine_cnn"]["module"] + ) + engine_cnn = getattr( + engine_cnn_module, model_params["engine_cnn"]["function"] + ) + # The original ResNet implementation use this padding, but we pad the images in the ImageMapper. + # x = tf.pad(telescope_data, tf.constant([[3, 3], [3, 3]]), name='conv1_pad') + init_layer = model_params.get("init_layer", False) + if init_layer: + network_input_img = tf.keras.layers.Conv2D( + filters=init_layer["filters"], + kernel_size=init_layer["kernel_size"], + strides=init_layer["strides"], + name=backbone_name + "_conv1_conv", + )(network_input_img) + # x = tf.pad(x, tf.constant([[1, 1], [1, 1]]), name='pool1_pad') + init_max_pool = model_params.get("init_max_pool", False) + if init_max_pool: + network_input_img = tf.keras.layers.MaxPool2D( + pool_size=init_max_pool["size"], + strides=init_max_pool["strides"], + name=backbone_name + "_pool1_pool", + )(network_input_img) + engine_output_cnn = engine_cnn( + network_input_img, params=model_params, name=backbone_name + ) + network_output = output_cnn = tf.keras.layers.GlobalAveragePooling2D( + name=backbone_name + "_global_avgpool" + )(engine_output_cnn) + + if data.prm_shape != None and data.mode == "train": + engine_mlp_module = importlib.import_module( + model_params["engine_mlp"]["module"] + ) + engine_mlp = getattr( + engine_mlp_module, model_params["engine_mlp"]["function"] + ) + engine_output_mlp = engine_mlp( + network_input_prm, params=model_params, name=backbone_name + ) + network_output = output_mlp = tf.keras.layers.Flatten()(engine_output_mlp) + if data.img_shape != None: + network_output = tf.keras.layers.Concatenate()([output_cnn, output_mlp]) + + singlecnn_model = tf.keras.Model( + network_input, network_output, name=backbone_name + ) + return singlecnn_model, network_input From 328ebb46ce3162720cf6c5ec1937f735d14053e7 Mon Sep 17 00:00:00 2001 From: Sahil Yadav <53268444+sahilyadav27@users.noreply.github.com> Date: Sat, 10 Dec 2022 18:45:46 +0530 Subject: [PATCH 13/15] Delete single_cnn.py --- ctlearn/default_models/single_cnn.py | 64 ---------------------------- 1 file changed, 64 deletions(-) delete mode 100644 ctlearn/default_models/single_cnn.py diff --git a/ctlearn/default_models/single_cnn.py b/ctlearn/default_models/single_cnn.py deleted file mode 100644 index 49f2784f..00000000 --- a/ctlearn/default_models/single_cnn.py +++ /dev/null @@ -1,64 +0,0 @@ -import importlib -import sys - -import tensorflow as tf - -def single_nn_model(data, model_params): - - # Load neural network model - network_input, network_output = [], [] - if data.img_shape != None: - network_input_img = tf.keras.Input(shape=data.img_shape, name=f"images") - network_input.append(network_input_img) - - if data.prm_shape != None and data.mode == "train": - network_input_prm = tf.keras.Input(shape=data.prm_shape, name=f"parameters") - network_input.append(network_input_prm) - - backbone_name = model_params.get("name", "SingleNN") + "_backbone" - trainable_backbone = model_params.get("trainable_backbone", True) - pretrained_weights = model_params.get("pretrained_weights", None) - if pretrained_weights: - loaded_model = tf.keras.models.load_model(pretrained_weights) - for layer in loaded_model.layers: - if "_backbone" in layer.name: - singlenn_model = loaded_model.get_layer(layer.name) - singlenn_model.trainable = trainable_backbone - else: - sys.path.append(model_params["model_directory"]) - if data.img_shape != None: - engine_cnn_module = importlib.import_module(model_params["engine_cnn"]["module"]) - engine_cnn = getattr(engine_cnn_module, model_params["engine_cnn"]["function"]) - # The original ResNet implementation use this padding, but we pad the images in the ImageMapper. - # x = tf.pad(telescope_data, tf.constant([[3, 3], [3, 3]]), name='conv1_pad') - init_layer = model_params.get("init_layer", False) - if init_layer: - network_input_img = tf.keras.layers.Conv2D( - filters=init_layer["filters"], - kernel_size=init_layer["kernel_size"], - strides=init_layer["strides"], - name=backbone_name + "_conv1_conv", - )(network_input_img) - # x = tf.pad(x, tf.constant([[1, 1], [1, 1]]), name='pool1_pad') - init_max_pool = model_params.get("init_max_pool", False) - if init_max_pool: - network_input_img = tf.keras.layers.MaxPool2D( - pool_size=init_max_pool["size"], - strides=init_max_pool["strides"], - name=backbone_name + "_pool1_pool", - )(network_input_img) - engine_output_cnn = engine_cnn(network_input_img, params=model_params, name=backbone_name) - network_output = output_cnn = tf.keras.layers.GlobalAveragePooling2D( - name=backbone_name + "_global_avgpool" - )(engine_output_cnn) - - if data.prm_shape != None and data.mode == "train": - engine_mlp_module = importlib.import_module(model_params["engine_mlp"]["module"]) - engine_mlp = getattr(engine_mlp_module, model_params["engine_mlp"]["function"]) - engine_output_mlp = engine_mlp(network_input_prm, params=model_params, name=backbone_name) - network_output = output_mlp = tf.keras.layers.Flatten()(engine_output_mlp) - if data.img_shape != None: - network_output = tf.keras.layers.Concatenate()([output_cnn, output_mlp]) - - singlenn_model = tf.keras.Model(network_input, network_output, name=backbone_name) - return singlenn_model, network_input From 2a7acb722aadced1399a86bba4c5675f6cb53ba9 Mon Sep 17 00:00:00 2001 From: Sahil Yadav <53268444+sahilyadav27@users.noreply.github.com> Date: Sat, 10 Dec 2022 18:46:43 +0530 Subject: [PATCH 14/15] Delete singleCNN_param.yml --- .../default_config_files/singleCNN_param.yml | 493 ------------------ 1 file changed, 493 deletions(-) delete mode 100644 ctlearn/default_config_files/singleCNN_param.yml diff --git a/ctlearn/default_config_files/singleCNN_param.yml b/ctlearn/default_config_files/singleCNN_param.yml deleted file mode 100644 index e42884db..00000000 --- a/ctlearn/default_config_files/singleCNN_param.yml +++ /dev/null @@ -1,493 +0,0 @@ -# Example config file containing all possible options for CTLearn, whether -# they're required or optional, their datatypes, and default arguments. -# A config file is only required for creating new models. Existing CTLearn -# benchmark models can be constructed from the command line. Please see the -# README for instructions. -# -# For an explanation of the data format and valid column names for the -# selection_string, array_info, and event_info Data config options, see -# https://github.com/cta-observatory/dl1-data-handler/wiki/CTA-ML-Data-Format -# or use ViTables http://vitables.org/ to examine the HDF5 files directly. - -# List of reconstruction tasks. For now it's recommended to you single task learning. -# Valid options: -# - 'particletype' -# - 'energy' -# - 'direction' -# These options have to be in consonance with the 'event_info' and -# 'transforms' in 'Data'. -# Requirements/recommendations: -# - 'particletype': -# event_info: -# - 'true_shower_primary_id' -# transforms: -# - name: 'ShowerPrimaryID' -# -# - 'energy': -# event_info: -# - 'true_energy' -# transforms: -# - name: 'MCEnergy' -# -# - 'direction': -# event_info: -# - 'true_energy' -# - 'true_alt' -# - 'true_az' -# transforms: -# - name: 'MCEnergy' -# - name: 'DeltaAltAz' -# -# Required list of strings. -Reco: ['energy'] - -Logging: - # Path to directory to store TensorFlow model checkpoints and summary plots. - # A timestamped copy of the configuration file will also be put here. - # Required string. - #model_directory: '/home/sahil/deeplearning' - -Data: - # Either a list of data file paths, - # or a path to a file listing data file paths, one per line. - # Required list or string. - #file_list: '/home/sahil/deeplearning/file_list.txt' - - # Type of examples to load. - # Optional string. Default: 'mono' - # Valid options: - # - 'mono': single images of one telescope type - # - 'stereo': stereoscopic images of events - mode: 'mono' - - # List of telescope types to load. - # Valid telescope types: - # - 'LST_LST_LSTCam': LST Telescope and Camera - # - 'LST_MAGIC_MAGICCam': MAGIC Telescopes - # - 'MST_MST_FlashCam': MST Telescope with FlashCAM Camera - # - 'MST_MST_NectarCam': MST Telescope with NectarCAM Camera - # - 'SST_SCT_SCTCam': SCT Telescope and Camera - # - 'SST_ASTRI_ASTRICam': SST-2M ASTRI Telescope and CHECH Camera - # Camera images from the following telescopes can be read, but writers - # for the data are not yet available: - # - FACT, HESS-I, HESS-II, VERITAS - # Required list of strings. - selected_telescope_types: ['LST_LST_LSTCam'] - - # Subset of telescope IDs to include of the selected telescope types. - # Optional list of integer values. - # Default: load all telescopes of the selected telescope types. - selected_telescope_ids: [1, 2, 3, 4] - - # Dict of multiplicity selection. - # Valid options: - # - 'telescope_types': int (from above) - # - 'Subarray': int (for full array multiplicity) - # Optinal dict. Not needed for MAGIC data! - #multiplicity_selection: {"LST_LST_LSTCam": 4} - parameter_list: ["hillas_intensity", "hillas_skewness", "hillas_kurtosis", "hillas_r", "hillas_phi", "hillas_length"] - # Dict of parameter selections from the DL1 file. - # The recommended way of applying quality cuts to the data. - # Only available for mono analysis at the moment. - # Optional dict. - parameter_selection: - - {col_name: "hillas_intensity", min_value: 50.0} - - {col_name: "leakage_intensity_width_2", max_value: 0.2} - - # Not the recommended way of applying quality cuts to the data. - # PyTables cut condition to apply selection cuts to events. - # Optional string. Default: don't apply any cuts - # See https://www.pytables.org/usersguide/condition_syntax.html - # for explanation of syntax. - #selection_string: '(true_energy > 1.0) & (true_h_first_int < 20000)' - - # Event selection filters to apply to each data file. - # Optional list of dictionaries with the following key/value pairs: - # - 'path': Optional string. Path to module containing filter. - # Default: path to DL1DataHandler - # - 'module': Optional string. Name of module containing filter. - # Default: 'utils' - # - 'name': Required string. Name of filter. - # - 'args': Optional dictionary. Arguments to pass to filter using - # filter(file, **args). Default: {} - # Valid filter names are those defined in DL1DataHandler or any defined - # in the specified path and module. - #event_selection: - # - - # name: 'event_intensity_filter' - # args: {i_min: 100, i_max: 316} - # - - # path: '/path/to/my/module/' - # module: 'my_filter' - # name: 'filter_fn' - # args: {'arg1': 'foo', 'arg2': 3.14} - - # Image selection filters to apply to each image (mono mode only). - # Optional list of dictionaries with the following key/value pairs: - # - 'path': Optional string. Path to module containing filter. - # Default: path to DL1DataHandler - # - 'module': Optional string. Name of module containing filter. - # Default: 'utils' - # - 'name': Required string. Name of filter. - # - 'args': Optional dictionary. Arguments to pass to filter using - # filter(file, **args). Default: {} - # Valid filter names are those defined in DL1DataHandler or any defined - # in the specified path and module. - #image_selection: - # - - # name: 'image_intensity_filter' - # args: {i_min: 10, i_max: 31.6} - # - - # path: '/path/to/my/module/' - # module: 'my_filter' - # name: 'filter_fn' - # args: {'arg1': 'foo', 'arg2': 3.14} - - # Whether to shuffle the examples. - # Optional Boolean. Default: False - shuffle: false - - # Seed for shuffling the examples. Only used if shuffle is true. - # Optional integer. Default: use default random initialization. - seed: 1234 - - # Image channels to load. - # Optional list of strings. Default: ['image'] - # Valid options are 'image', 'peak_time' 'cleaned_image' and 'clean_peak_time', or whichever columns are in - # the telescope tables of your data files. - image_channels: ['image', 'peak_time'] - - # Settings passed directly as arguments to ImageMapper. - # Optional dictionary. Default: {} - # - # The camera types supported by ImageMapper that can be used in - # the settings below are 'ASTRICam', 'CHEC', 'DigiCam', 'FACT', - # 'FlashCam', 'HESS-I', 'HESS-II', 'LSTCam', 'MAGICCam', 'NectarCam', - # 'SCTCam', and 'VERITAS'. - mapping_settings: - - # List of camera types to calculate mapping tables for. - # Optional list of camera type strings. - # Default: calculate mapping tables for all supported camera types - camera_types: ['LSTCam'] - - # Algorithm to convert image vectors to rectangular arrays - # Optional dictionary with string keys and string values. - # Default: 'oversampling' for all camera types not in the dictionary - # Valid keys are any camera types supported by ImageMapper. - # Valid mapping method options (values): - # - 'oversampling': Convert each hexagonal pixel to four square - # pixels and reweight the charge to realign to a square grid - # - 'rebinning': Interpret the intensity as a histogram and rebin - # the hexagonal histogram into a square one. - # - 'nearest_interpolation': Perform nearest neighbor - # - 'bilinear_interpolation': Draw Delaunay triangulation and - # perform bilinear interpolation - # - 'bicubic_interpolation': Draw Delaunay triangulation and - # perform bicubic interpolation - # - 'image_shifting': Shift pixels of alternate rows (hexagonal - # cameras only) - # - 'axial_addressing': Warp images by relabeling axes (hexagonal - # cameras only) - mapping_method: - 'LSTCam': 'bilinear_interpolation' - 'FlashCam': 'bilinear_interpolation' - 'NectarCam': 'bilinear_interpolation' - 'SCTCam': 'oversampling' - 'CHEC': 'oversampling' - 'MAGICCam': 'bilinear_interpolation' - - # Number of padding pixels to add around each edge of the mapped image. - # A value of 1 will increase both the image height and width by 2, etc. - # Optional dictionary with camera type string keys and integer values. - # Default: 0 for any camera type not specified - padding: - 'LSTCam': 2 - 'FlashCam': 1 - 'NectarCam': 2 - 'SCTCam': 0 - 'CHEC': 0 - 'MAGICCam': 2 - - # Shape of mapped image to return. Used only for mapping methods - # without a fixed output shape: rebinning, nearest interpolation, - # bilinear interpolation, bicubic interpolation - # Optional dictionary with camera type string keys and values that - # are lists of three integers: (, , ) - interpolation_image_shape: - 'LSTCam': [110, 110, 1] - - # Explicitly set output grid points outside the camera to 0 - # when performing bilinear and bicubic interpolation. - # Optional Boolean. Default: false - mask_interpolation: false - - # Auxiliary information to return from the Array Information table. - # Optional list of strings. Default: return no array info - # Valid options are columns in the Array_Information table. - #array_info: ['x', 'y', 'z'] - - # Auxiliary information to return from the Events table. - # Optional list of strings. Default: return no event info - # Valid options are columns in the Events table. - # These options have to be in consonance with the 'label_names' in 'Model'. - event_info: ['true_shower_primary_id', 'true_energy', 'true_alt', 'true_az'] - - # Transforms to apply to the data, in order. - # Optional list of dictionaries with the following key/value pairs: - # - 'path': Optional string. Path to module containing Transform. - # Default: path to DL1DataHandler - # - 'module': Optional string. Name of module containing Transform. - # Default: 'processor' - # - 'name': Required string. Name of Transform. - # - 'args': Optional dictionary. Arguments to pass to transform using - # Transform(**args). Default: {} - # Valid transform names are those defined in DL1DataHandler or any defined - # in the specified path and module. - transforms: - - - name: 'MCEnergy' - # - - # path: '/path/to/my/module/' - # module: 'my_transform' - # name: 'MyTransform' - # args: {'arg1': 'foo', 'arg2': 3.14} - - # Whether to validate that the shape and dtype of the processed data - # matches the example description. - # Recommended setting is True while developing the network and False - # during production. - # Optional Boolean. Default: False - validate_processor: False - -# Settings for the Keras batch generator. -Input: - - # Number of consecutive examples to combine into a batch for a single gpu. - # Optional integer. Default: 1 - batch_size_per_worker: 32 - - # Whether to concatenate the stereo images from an event to feed it - # to a monoscopic model. - # Optional boolean. Default: false - concat_telescopes: false - -# Settings for the TensorFlow model. The options in this and the -# Model Parameters section are passed to the Estimator model_fn -# and the user's model function. -Model: - - # Path to directory containing model module. - # Optional string or null. Default if missing or null is to load - # CTLearn default models directory: 'installation_path/ctlearn/ctlearn/default_models/' - #model_directory: '/my/model/path/' - - # Name of the constructed model. - # Optional string or null. - name: 'SingleCNN' - - # Required dictionary containing a module/function pair. - # Module in model directory and function in module implementing the model. - # Module and function pairs included with CTLearn: - # - {module: 'single_cnn', function: 'single_cnn_model'}: monoscopic - # model using a basic convolutional neural network (CNN) - # or residual blocks (ResNets) - # - {module: 'cnn_rnn', function: 'cnn_rnn_model'}: array model - # feeding output of a basic CNN or a ResNet for each telescope - # into a recurrent neural network (RNN) - backbone: {module: 'single_cnn', function: 'single_cnn_model'} - - # Required dict with keys 'module' and 'function' & string values. - # Module and function for the CTLearn backbone. - # Valid options: - # - {module: 'basic', function: 'conv_block'} - # - {module: 'resnet', function: 'stacked_res_blocks'} - engine_cnn: {module: 'basic', function: 'conv_block'} - engine_mlp: {module: 'basic', function: 'fully_connect'} - # Optional arguments for the first Conv2D and MaxPool layer - # before the selected model. - #init_layer: {filters: 64, kernel_size: 7, strides: 1} - #init_max_pool: {size: 3, strides: 2} - - # Required dict with keys 'module' and 'function' & string values. - # Module and function for the CTLearn head. - # Valid options: - # - {module: 'head', function: 'standard_head'} - head: {module: 'head', function: 'standard_head'} - - # Required string or null. - # Path to a checkpoint file or model directory from which to load - # pretrained network weights. If null, don't load any weights. - pretrained_weights: null - - # Optional float. Default: 0.5 - # Dropout rate of dropout layers in the CNNRNN model. - dropout_rate: 0.5 - -# The options in this and the Model section are passed in a dictionary -# called "params" to the model function. -# The config option 'model_directory' above is included in params as well. -# None of these options are accessed anywhere outside the model, so -# arbitrary options may be added here. This permits custom configuration -# of user-provided models. -# Below are listed the configuration options for the CTLearn included -# models, which are only accessed if using those models. -Model Parameters: - basic: - - conv_block: - # Required list of dicts with keys 'filters', 'kernel_size' and number - # with integer values. - # If number value is not stored will be automatically set to 1 - # Filter dimension and kernel size for the CNN block - # convolutional layers. - # Number for the desired number of convolutional layers - layers: - - {filters: 32, kernel_size: 3, number: 1} - - {filters: 64, kernel_size: 3, number: 1} - - {filters: 128, kernel_size: 3, number: 1} - - # Required dictionary with keys 'size' and 'strides' and - # integer values, or null. - # Max pool size and strides. If null, don't perform any pooling. - max_pool: {size: 2, strides: 2} - - # Required integer or null. - # Number of output filters of a final 1x1 convolutional layer. - # If null, don't include this bottleneck layer. - bottleneck: null - - # Optional Boolean. Default: false - # Whether to include a batch normalization layer after each - # convolutional layer. Exercise caution when using with - # array-level models. - batchnorm: false - - fully_connect: - # Required list of integers. - # Number of units for each fully-connected head dense layer. - layers: [1024, 512, 256, 128] - - # Optional Boolean. Default: false - # Whether to include a batch normalization layer after each - # dense layer. - batchnorm: false - - conv_head: - # Required list of dicts with keys 'filters' and 'kernel_size' - # with integer values. - # Filter dimension and kernel size for the convolutional - # network head layers. - layers: - - {filters: 64, kernel_size: 3} - - {filters: 128, kernel_size: 3} - - {filters: 256, kernel_size: 3} - - # Optional Boolean. Default: true - # Whether to perform average pooling over spatial dimensions - # of the convolutional output before calculating final output. - final_avg_pool: true - - # Optional Boolean. Default: false - # Whether to include a batch normalization layer after each - # convolutional layer. - batchnorm: false - - # Optional float. Default: 0.99 - # Decay parameter for batch normalization layers. - batchnorm_decay: 0.99 - - resnet: - stacked_res_blocks: - # Optional string. Default: 'bottleneck' - # Type of the residual block. - # Valid options: - # - 'basic' - # - 'bottleneck' - residual_block: 'bottleneck' - - # Required list of dicts with keys 'filters' and 'blocks' - # with integer values. - # Filter dimension and number of blocks for the ResNet - # architecture. - # Typical ResNet architectures: - # Thin-ResNet - #- {filters: 48, blocks: 2} - #- {filters: 96, blocks: 3} - #- {filters: 128, blocks: 3} - #- {filters: 256, blocks: 3} - # ResNet50 - #- {filters: 64, blocks: 3} - #- {filters: 128, blocks: 4} - #- {filters: 256, blocks: 6} - #- {filters: 512, blocks: 3} - architecture: - - {filters: 48, blocks: 2} - - {filters: 96, blocks: 3} - - {filters: 128, blocks: 3} - - {filters: 256, blocks: 3} - - # Dictionary of tasks where the values contain the fully connected layers - # head of each reconstruction task. The final loss is calculated with a weighted sum - # over the individual losses. Currently the weights are constanst values. - # For the classification task, the class names are passed into the dict - # in order of class label (0 to n-1). - standard_head: - particletype: {class_names: ['proton', 'gamma'], fc_head: [512, 256, 2], weight: 1.0} - energy: {fc_head: [512, 256, 1], weight: 1.0} - direction: {fc_head: [512, 256, 2], weight: 1.0} - - # Optional dict of attention mechanisms. - # Valid options: - # Dual attention (Spatial and channel squeeze-and-excitation attention) - # - {mechanism: 'Squeeze-and-Excitation', ratio: 16} - # Channel Squeeze-and-excitation attention - # - {mechanism: 'Channel-Squeeze-and-Excitation', ratio: 4} - # Spatial squeeze-and-excitatiom attention - # - {mechanism: 'Spatial-Squeeze-and-Excitation'} - # References: - # - [Squeeze and Excitation Networks](https://arxiv.org/abs/1709.01507) - # - [Concurrent Spatial and Channel Squeeze & Excitation in Fully Convolutional Networks](https://arxiv.org/abs/1803.02579) - attention: {mechanism: 'Squeeze-and-Excitation', ratio: 16} - -Training: - - # Optional float. Default: 0.1 - # Randomly chosen fraction of data to set aside for validation. - validation_split: 0.1 - - # Required number of epochs on which to train. - num_epochs: 20 - - # Required string. - # Valid options: ['Adadelta', 'Adam', 'RMSProp', 'SGD'] - # Optimizer function for training. - optimizer: 'Adam' - - # Optional float. Required if optimizer is 'Adam', ignored otherwise. - # Epsilon parameter for the Adam optimizer. - adam_epsilon: 1.0e-8 - - # Required integer. - # Base learning rate before scaling or annealing. - base_learning_rate: 0.001 - - # Optional integer and floats. - # Reducing the learning rate after the network stops learning. - lr_reducing_patience: 5 - lr_reducing_factor: 0.5 - lr_reducing_mindelta: 0.01 - lr_reducing_minlr: 0.00001 - -Prediction: - - # Required string if running in predict mode. - # Name of the file to save predictions. - prediction_file: ./ctlearn_prediction.h5 - - # A dict of either a list of data file paths, - # or a path to a file listing data file paths, one per line. - # Required dict of list or string if running in predict mode. - prediction_file_lists: - prediction_file_list1.h5: /tmp/dataset/prediction_file_list1.txt - prediction_file_list2.h5: /tmp/dataset/prediction_file_list2.txt From c27937f5dfdf78ecae0857fa8224cc673e2274ef Mon Sep 17 00:00:00 2001 From: Sahil Yadav <53268444+sahilyadav27@users.noreply.github.com> Date: Sat, 10 Dec 2022 18:49:10 +0530 Subject: [PATCH 15/15] Update single_nn.py --- ctlearn/default_models/single_nn.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ctlearn/default_models/single_nn.py b/ctlearn/default_models/single_nn.py index b28cd1c5..6953e585 100644 --- a/ctlearn/default_models/single_nn.py +++ b/ctlearn/default_models/single_nn.py @@ -4,7 +4,7 @@ import tensorflow as tf -def single_cnn_model(data, model_params): +def single_nn_model(data, model_params): # Load neural network model network_input, network_output = [], [] @@ -23,8 +23,8 @@ def single_cnn_model(data, model_params): loaded_model = tf.keras.models.load_model(pretrained_weights) for layer in loaded_model.layers: if "_backbone" in layer.name: - singlecnn_model = loaded_model.get_layer(layer.name) - singlecnn_model.trainable = trainable_backbone + singlenn_model = loaded_model.get_layer(layer.name) + singlenn_model.trainable = trainable_backbone else: sys.path.append(model_params["model_directory"]) if data.img_shape != None: @@ -73,7 +73,7 @@ def single_cnn_model(data, model_params): if data.img_shape != None: network_output = tf.keras.layers.Concatenate()([output_cnn, output_mlp]) - singlecnn_model = tf.keras.Model( + singlenn_model = tf.keras.Model( network_input, network_output, name=backbone_name ) - return singlecnn_model, network_input + return singlenn_model, network_input