diff --git a/docs/index.html b/docs/index.html index ca19fdd..910adf2 100644 --- a/docs/index.html +++ b/docs/index.html @@ -883,22 +883,84 @@

Model Architecturemodel=CreateModel((13,21,2),n_filters=5,pool_size=3) model.summary() -This generates a model with the following architecture: -| Type | Output Shape | Parameters | -|----------------------|---------------------|------------| -| InputLayer | (None, 13, 21, 2)| 0 | -| QSeparableConv2D | (None, 11, 19, 5)| 33 | -| QActivation | (None, 11, 19, 5)| 0 | -| QConv2D | (None, 11, 19, 5)| 30 | -| QActivation | (None, 11, 19, 5)| 0 | -| AveragePooling2D | (None, 3, 6, 5) | 0 | -| QActivation | (None, 3, 6, 5) | 0 | -| Flatten | (None, 90) | 0 | -| QDense | (None, 16) | 1456 | -| QActivation | (None, 16) | 0 | -| QDense | (None, 16) | 272 | -| QActivation | (None, 16) | 0 | -| QDense | (None, 14) | 238 |

+This generates a model with the following architecture:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
TypeOutput ShapeParameters
InputLayer(None, 13, 21, 2)0
QSeparableConv2D(None, 11, 19, 5)33
QActivation(None, 11, 19, 5)0
QConv2D(None, 11, 19, 5)30
QActivation(None, 11, 19, 5)0
AveragePooling2D(None, 3, 6, 5)0
QActivation(None, 3, 6, 5)0
Flatten(None, 90)0
QDense(None, 16)1456
QActivation(None, 16)0
QDense(None, 16)272
QActivation(None, 16)0
QDense(None, 14)238
+

Model Evaluation#

Refer to Evaluate for more details

diff --git a/docs/search/search_index.json b/docs/search/search_index.json index e384095..9e4519d 100644 --- a/docs/search/search_index.json +++ b/docs/search/search_index.json @@ -1 +1 @@ -{"config":{"lang":["en"],"separator":"[\\s\\-]+","pipeline":["stopWordFilter"]},"docs":[{"location":"index.html","title":"Smart Pixels (ML)","text":"

Smart Pixels is a project focused on implementing machine learning models directly on silicon pixels or future detectors to enhance the inference of charged particle track parameters. We here use an MDN (Mixture Density Network) with one Gaussian. This model predicts the mean value of the target variable and the associated uncertainty to that prediction, with NLL (Negative Log-likelihood Loss) as the loss function to minimize.

"},{"location":"index.html#table-of-contents","title":"Table of Contents","text":""},{"location":"index.html#getting-started","title":"Getting Started","text":""},{"location":"index.html#installation","title":"Installation","text":"
  1. Clone the repository:
    git clone https://github.com/smart-pix/smart-pixels-ml.git\ncd smart-pixels-ml\npip install -r requirements.txt\n
    Testing successful installation by running
    python test_run.py`\n
    The test run should perform a basic smoke test to check if the installation is successful and basic things that we need are working fine. Details can be found in Testing

    The output should look like this:

"},{"location":"index.html#usage","title":"Usage","text":"

For the usage guide refer to Usage Guide

"},{"location":"index.html#dataset","title":"Dataset","text":"

Download the simulated data from: zenodo and PixelAV

"},{"location":"index.html#structure","title":"Structure","text":""},{"location":"index.html#data-visualization","title":"Data Visualization","text":"

For visualization of the how the input data looks like, we have to define the path towards the dataX and optionally to the labels as

import pandas as pd\nimport matplotlib.pyplot as plt\n\ndataX = pd.read_parquet(\"path/to/recon3D_data_file\")\nlabels_df = pd.read_parquet(\"path/to/labels_data_file\")\nreshaped_dataX = dataX.values.reshape((len(dataX), 20, 13, 21))\n\nprint(labels_df.iloc[0])\nplt.imshow(reshaped_dataX[0, 0, :, :], cmap='coolwarm')  # first time-step\nplt.show()\nplt.imshow(reshaped_dataX[0, -1, :, :], cmap='coolwarm')  # last time-step\nplt.show()\n

"},{"location":"index.html#data-generator","title":"Data Generator","text":"

Due to the large size of the dataset, the entire dataset can not be loaded into RAM. Hence, we use data generators to load the dataset on the fly during training with inbuilt quantization, standardization, shuffling, etc. Refer to data generator for more details.

"},{"location":"index.html#testing","title":"Testing","text":"

To test that everything is working fine try running the simple test_run.py file as

python test_run.py\n

"},{"location":"index.html#model-architecture","title":"Model Architecture","text":"

The core model architecture is defined in model.py, which provides the baseline MDN architecture with quantized neural network layers. We use the Negative Log-Likelihood (NLL) as the loss function implemented in loss.py. A good reading about it can be found here

Refer to Model and Loss for more details.

As an example, to implement the model with 2 time slices:

from model import *\n\nmodel=CreateModel((13,21,2),n_filters=5,pool_size=3)\nmodel.summary()\n
This generates a model with the following architecture: | Type | Output Shape | Parameters | |----------------------|---------------------|------------| | InputLayer | (None, 13, 21, 2)| 0 | | QSeparableConv2D | (None, 11, 19, 5)| 33 | | QActivation | (None, 11, 19, 5)| 0 | | QConv2D | (None, 11, 19, 5)| 30 | | QActivation | (None, 11, 19, 5)| 0 | | AveragePooling2D | (None, 3, 6, 5) | 0 | | QActivation | (None, 3, 6, 5) | 0 | | Flatten | (None, 90) | 0 | | QDense | (None, 16) | 1456 | | QActivation | (None, 16) | 0 | | QDense | (None, 16) | 272 | | QActivation | (None, 16) | 0 | | QDense | (None, 14) | 238 |

"},{"location":"index.html#model-evaluation","title":"Model Evaluation","text":"

Refer to Evaluate for more details

"},{"location":"plot.html","title":"Plots","text":"

Add things about the plots here

"},{"location":"testing.html","title":"Testing Module","text":"

This module contains unit tests for the Smart Pixels ML project.

"},{"location":"testing.html#scripts","title":"Scripts","text":""},{"location":"testing.html#test_runpy","title":"test_run().py","text":""},{"location":"testing.html#functions","title":"Functions","text":"
  1. check_directories()

    • Description: Checks if the essential directories (TEST_ROOT, DATA_DIR, LABELS_DIR, TFRECORDS_DIR, etc.) exist. Logs an error if any directory is missing.
    • Returns: True if all required directories exist; otherwise, logs an error and returns False.
  2. generate_dummy_data(num_files=NUM_DUMMY_FILES)

    • Description: Generates dummy Parquet files for testing, including random input data and labels.
    • Parameters: num_files (int): The number of dummy data files to generate.
    • Outputs: Creates Parquet files in DATA_DIR and LABELS_DIR.
  3. generate_tfrecords()

    • Description: Initializes data generators and generates TFRecords for training and validation datasets.
    • Outputs: TFRecord files saved in TFRECORDS_DIR_TRAIN and TFRECORDS_DIR_VALIDATION.
  4. load_tfrecords():

    • Description: Loads pre-generated TFRecords for training and validation datasets.
    • Returns: training_generator and validation_generator.
  5. test_model_generation()

    • Description: Builds and compiles a test model using the CreateModel function.
    • Returns: A compiled Keras model.
    • Raises: Logs an error and exits if the model cannot be built.
  6. test_train_model()

    • Description: Tests model training by generating dummy data, creating TFRecords, and training the model.
    • Outputs: Logs training progress, final validation loss, and saves model weights during training.
  7. run_smoke_test():

    • Description: Runs the entire smoke test, including data generation, model training, and evaluation.
    • Outputs: Logs the final evaluation metrics and saves the model.
"},{"location":"testing.html#some_testpy","title":"some_test.py","text":""},{"location":"testing.html#functions_1","title":"Functions","text":"

...

"},{"location":"testing.html#todo","title":"TODO \ud83d\udcdd","text":""},{"location":"usage.html","title":"Usage Guide","text":"

This is a guide for using the Smart Pixels ML project to train and evaluate the models on the simulated data.

"},{"location":"usage.html#1-installation","title":"1. Installation","text":"

Refer to Readme for installation instructions.

"},{"location":"usage.html#2-data-collection","title":"2. Data Collection","text":"

Download the simulated data from zenodo and PixelAV Add other links here

Ensure the two directories Data and Labels are present.

"},{"location":"usage.html#3-data-preparation","title":"3. Data Preparation","text":""},{"location":"usage.html#4-model-creation","title":"4. Model Creation","text":""},{"location":"usage.html#5-model-training","title":"5. Model Training","text":"

If everything is set up correctly, the training should start and run seamlessly. For example:

model.fit(\n    x=training_generator, \n    validation_data=validation_generator, \n    epochs=200, \n    verbose=1)\n

After training, check the loss and accuracy of the model. And save the model weights.

"},{"location":"usage.html#6-model-evaluation","title":"6. Model Evaluation","text":"

Initiate the model and Load the weights as

model=CreateModel((13,21,2),n_filters=5,pool_size=3)\nmodel.load_weights(\"model_weights.h5\")\n
And then evaluate the model as done in evaluate.py or in evaluate.py

"},{"location":"usage.html#7-model-prediction","title":"7. Model Prediction","text":"

Look at predict

"},{"location":"usage.html#8-add-additional-instructions","title":"8. Add Additional Instructions","text":"

Here are some additional instructions

"},{"location":"api/data_generator.html","title":"datagenerator module","text":"

This module contains the OptimizedDataGenerator class, which generates batches of data for training and validation during model training. This datagenerator handles the loading and processing of the data, including shuffling, standardization, and quantization of the data. It does by pre-processing the data and saving it as TFRecord files and then loading the batches on the fly during training.

"},{"location":"api/data_generator.html#methods","title":"Methods","text":""},{"location":"api/data_generator.html#__init__","title":"__init__(...)","text":"

Initialize the OptimizedDataGenerator class with the specified parameters to configure the data generator for preprocessing and batching.

"},{"location":"api/data_generator.html#arguments","title":"Arguments","text":"

Described in the comments of the __init__ method of the OptimizedDataGenerator.py file.

"},{"location":"api/data_generator.html#example-usage","title":"Example Usage","text":""},{"location":"api/data_generator.html#initializing-the-data-generators","title":"Initializing the Data Generators","text":"
training_generator = OptimizedDataGenerator(\n    data_directory_path = \"path/to/data/\",\n    labels_directory_path = \"path/to/labels/\",\n    is_directory_recursive = False,\n    file_type = \"parquet\",\n    data_format = \"3D\",\n    batch_size = val_batch_size,\n    file_count = val_file_size,\n    to_standardize= True,\n    include_y_local= False,\n    labels_list = ['x-midplane','y-midplane','cotAlpha','cotBeta'],\n    input_shape = (2,13,21), # (20,13,21),\n    transpose = (0,2,3,1),\n    shuffle = False, \n    files_from_end=True,\n\n    tfrecords_dir = \"path/to/tfrecords/\",\n    use_time_stamps = [0, 19], #-1\n    max_workers = 1, # Don't make this too large (will use up all RAM)\n    seed = 10, \n    quantize = True # Quantization ON\n)\n
"},{"location":"api/data_generator.html#loading-the-data-generators","title":"Loading the Data Generators","text":"

Already generated TFRecords can be reused by setting load_from_tfrecords_dir as

training_generator = OptimizedDataGenerator(\n    load_from_tfrecords_dir = \"path/to/tfrecords/\",\n    shuffle = True,\n    seed = 13,\n    quantize = True\n)\n

The same goes for the validation generator.

"},{"location":"api/data_generator.html#using-the-data-generators","title":"Using the Data Generators","text":"

The data generators can be directly passed to the fit method of a Keras model.

history = model.fit(\n                        x=training_generator,\n                        validation_data=validation_generator,\n                        #callbacks=[es, mcp, csv_logger],\n                        epochs=1000,\n                        shuffle=False,\n                        verbose=1\n )\n
"},{"location":"api/evaluate.html","title":"Evaluate Module","text":"

The evaluate.py file defines the evaluation function for the model.

"},{"location":"api/evaluate.html#functions-evaluateconfig","title":"Functions: evaluate(config)","text":""},{"location":"api/evaluate.html#example-usage","title":"Example Usage:","text":"
config = {\n    \"weightsPath\": \"path/to/weights.hdf5\",\n    \"outFileName\": \"path/to/evaluation_results.csv\",\n    \"data_directory_path\": \"path/to/data/\",\n    \"labels_directory_path\": \"path/to/labels/\",\n    \"n_filters\": 5,\n    \"pool_size\": 3,\n    \"val_batch_size\": 500,\n    \"val_file_size\": 10\n}\nevaluate(config)\n
"},{"location":"api/loss.html","title":"Loss Module","text":"

This module uses a Mixture Density Network(MDN) and hence a negative log-likelihood loss function. It uses TensorFlow and TensorFlow Probability for the loss computation.

"},{"location":"api/loss.html#loss-function","title":"Loss Function","text":""},{"location":"api/loss.html#custom_lossy-p_base-minval1e-9-maxval1e9-scale512","title":"custom_loss(y, p_base, minval=1e-9, maxval=1e9, scale=512)","text":"

Calculates the Negative Log-Likelihood (NLL) for a batch of data using the model's predicted parameters.

"},{"location":"api/loss.html#brief-description","title":"Brief Description","text":"

The model parameters are the mean and the lower triangular part of the covariance matrix.

loss function is vectorized with batches.

"},{"location":"api/loss.html#arguments","title":"Arguments","text":""},{"location":"api/loss.html#returns","title":"Returns","text":""},{"location":"api/loss.html#example-usage","title":"Example Usage","text":"
import tensorflow as tf\nfrom tensorflow.keras.optimizers import Adam\nfrom loss import custom_loss\nfrom models import CreateModel\n\nmodel = CreateModel((13, 21, 2), n_filters=5, pool_size=3)\nmodel.compile(optimizer=Adam(learning_rate=0.001), loss=custom_loss)\n
"},{"location":"api/models.html","title":"Models Module","text":"

The models.py file defines Mixture Density Network (MDN) network with a 4D Multivariate Normal Distribution neural network architecture using quantized layers. The implementation uses QKeras to quantize the weights and activations of the network.

"},{"location":"api/models.html#functions","title":"Functions","text":""},{"location":"api/models.html#createmodelshape-n_filters-pool_size","title":"CreateModel(shape, n_filters, pool_size)","text":"

Creates a quantized neural network model for regression task with quantized layers and activations as in Model. The model has 14 output nodes with 4 being the target variables and the rest 10 being the co-variances.

model = CreateModel((13, 21, 2), n_filters=5, pool_size=3) model.summary()

"},{"location":"api/models.html#additional-helper-functions","title":"Additional Helper Functions","text":""},{"location":"api/models.html#conv_networkvar-n_filters5-kernel_size3","title":"conv_network(var, n_filters=5, kernel_size=3)","text":"

Defines the convolutional network block, with quantized layers and activations.

"},{"location":"api/models.html#var_networkvar-hidden10-output2","title":"var_network(var, hidden=10, output=2)","text":"

Defines the dense network block, with quantized layers and activations.

"},{"location":"api/plotting.html","title":"Plot Module","text":"

Add Plot results here

"},{"location":"api/utils.html","title":"Utils Module","text":"

This module contains utility functions to manage file operations and GPU configurations.

"},{"location":"api/utils.html#functions","title":"Functions","text":""},{"location":"api/utils.html#safe_remove_directorydirectory_path","title":"safe_remove_directory(directory_path)","text":"

Safely removes a directory if it exists.

"},{"location":"api/utils.html#check_gpu","title":"check_GPU()","text":"

Checks for available GPUs and sets memory growth to prevent allocation issues.

"}]} \ No newline at end of file +{"config":{"lang":["en"],"separator":"[\\s\\-]+","pipeline":["stopWordFilter"]},"docs":[{"location":"index.html","title":"Smart Pixels (ML)","text":"

Smart Pixels is a project focused on implementing machine learning models directly on silicon pixels or future detectors to enhance the inference of charged particle track parameters. We here use an MDN (Mixture Density Network) with one Gaussian. This model predicts the mean value of the target variable and the associated uncertainty to that prediction, with NLL (Negative Log-likelihood Loss) as the loss function to minimize.

"},{"location":"index.html#table-of-contents","title":"Table of Contents","text":""},{"location":"index.html#getting-started","title":"Getting Started","text":""},{"location":"index.html#installation","title":"Installation","text":"
  1. Clone the repository:
    git clone https://github.com/smart-pix/smart-pixels-ml.git\ncd smart-pixels-ml\npip install -r requirements.txt\n
    Testing successful installation by running
    python test_run.py`\n
    The test run should perform a basic smoke test to check if the installation is successful and basic things that we need are working fine. Details can be found in Testing

    The output should look like this:

"},{"location":"index.html#usage","title":"Usage","text":"

For the usage guide refer to Usage Guide

"},{"location":"index.html#dataset","title":"Dataset","text":"

Download the simulated data from: zenodo and PixelAV

"},{"location":"index.html#structure","title":"Structure","text":""},{"location":"index.html#data-visualization","title":"Data Visualization","text":"

For visualization of the how the input data looks like, we have to define the path towards the dataX and optionally to the labels as

import pandas as pd\nimport matplotlib.pyplot as plt\n\ndataX = pd.read_parquet(\"path/to/recon3D_data_file\")\nlabels_df = pd.read_parquet(\"path/to/labels_data_file\")\nreshaped_dataX = dataX.values.reshape((len(dataX), 20, 13, 21))\n\nprint(labels_df.iloc[0])\nplt.imshow(reshaped_dataX[0, 0, :, :], cmap='coolwarm')  # first time-step\nplt.show()\nplt.imshow(reshaped_dataX[0, -1, :, :], cmap='coolwarm')  # last time-step\nplt.show()\n

"},{"location":"index.html#data-generator","title":"Data Generator","text":"

Due to the large size of the dataset, the entire dataset can not be loaded into RAM. Hence, we use data generators to load the dataset on the fly during training with inbuilt quantization, standardization, shuffling, etc. Refer to data generator for more details.

"},{"location":"index.html#testing","title":"Testing","text":"

To test that everything is working fine try running the simple test_run.py file as

python test_run.py\n

"},{"location":"index.html#model-architecture","title":"Model Architecture","text":"

The core model architecture is defined in model.py, which provides the baseline MDN architecture with quantized neural network layers. We use the Negative Log-Likelihood (NLL) as the loss function implemented in loss.py. A good reading about it can be found here

Refer to Model and Loss for more details.

As an example, to implement the model with 2 time slices:

from model import *\n\nmodel=CreateModel((13,21,2),n_filters=5,pool_size=3)\nmodel.summary()\n
This generates a model with the following architecture:

Type Output Shape Parameters InputLayer (None, 13, 21, 2) 0 QSeparableConv2D (None, 11, 19, 5) 33 QActivation (None, 11, 19, 5) 0 QConv2D (None, 11, 19, 5) 30 QActivation (None, 11, 19, 5) 0 AveragePooling2D (None, 3, 6, 5) 0 QActivation (None, 3, 6, 5) 0 Flatten (None, 90) 0 QDense (None, 16) 1456 QActivation (None, 16) 0 QDense (None, 16) 272 QActivation (None, 16) 0 QDense (None, 14) 238"},{"location":"index.html#model-evaluation","title":"Model Evaluation","text":"

Refer to Evaluate for more details

"},{"location":"plot.html","title":"Plots","text":"

Add things about the plots here

"},{"location":"testing.html","title":"Testing Module","text":"

This module contains unit tests for the Smart Pixels ML project.

"},{"location":"testing.html#scripts","title":"Scripts","text":""},{"location":"testing.html#test_runpy","title":"test_run().py","text":""},{"location":"testing.html#functions","title":"Functions","text":"
  1. check_directories()

    • Description: Checks if the essential directories (TEST_ROOT, DATA_DIR, LABELS_DIR, TFRECORDS_DIR, etc.) exist. Logs an error if any directory is missing.
    • Returns: True if all required directories exist; otherwise, logs an error and returns False.
  2. generate_dummy_data(num_files=NUM_DUMMY_FILES)

    • Description: Generates dummy Parquet files for testing, including random input data and labels.
    • Parameters: num_files (int): The number of dummy data files to generate.
    • Outputs: Creates Parquet files in DATA_DIR and LABELS_DIR.
  3. generate_tfrecords()

    • Description: Initializes data generators and generates TFRecords for training and validation datasets.
    • Outputs: TFRecord files saved in TFRECORDS_DIR_TRAIN and TFRECORDS_DIR_VALIDATION.
  4. load_tfrecords():

    • Description: Loads pre-generated TFRecords for training and validation datasets.
    • Returns: training_generator and validation_generator.
  5. test_model_generation()

    • Description: Builds and compiles a test model using the CreateModel function.
    • Returns: A compiled Keras model.
    • Raises: Logs an error and exits if the model cannot be built.
  6. test_train_model()

    • Description: Tests model training by generating dummy data, creating TFRecords, and training the model.
    • Outputs: Logs training progress, final validation loss, and saves model weights during training.
  7. run_smoke_test():

    • Description: Runs the entire smoke test, including data generation, model training, and evaluation.
    • Outputs: Logs the final evaluation metrics and saves the model.
"},{"location":"testing.html#some_testpy","title":"some_test.py","text":""},{"location":"testing.html#functions_1","title":"Functions","text":"

...

"},{"location":"testing.html#todo","title":"TODO \ud83d\udcdd","text":""},{"location":"usage.html","title":"Usage Guide","text":"

This is a guide for using the Smart Pixels ML project to train and evaluate the models on the simulated data.

"},{"location":"usage.html#1-installation","title":"1. Installation","text":"

Refer to Readme for installation instructions.

"},{"location":"usage.html#2-data-collection","title":"2. Data Collection","text":"

Download the simulated data from zenodo and PixelAV Add other links here

Ensure the two directories Data and Labels are present.

"},{"location":"usage.html#3-data-preparation","title":"3. Data Preparation","text":""},{"location":"usage.html#4-model-creation","title":"4. Model Creation","text":""},{"location":"usage.html#5-model-training","title":"5. Model Training","text":"

If everything is set up correctly, the training should start and run seamlessly. For example:

model.fit(\n    x=training_generator, \n    validation_data=validation_generator, \n    epochs=200, \n    verbose=1)\n

After training, check the loss and accuracy of the model. And save the model weights.

"},{"location":"usage.html#6-model-evaluation","title":"6. Model Evaluation","text":"

Initiate the model and Load the weights as

model=CreateModel((13,21,2),n_filters=5,pool_size=3)\nmodel.load_weights(\"model_weights.h5\")\n
And then evaluate the model as done in evaluate.py or in evaluate.py

"},{"location":"usage.html#7-model-prediction","title":"7. Model Prediction","text":"

Look at predict

"},{"location":"usage.html#8-add-additional-instructions","title":"8. Add Additional Instructions","text":"

Here are some additional instructions

"},{"location":"api/data_generator.html","title":"datagenerator module","text":"

This module contains the OptimizedDataGenerator class, which generates batches of data for training and validation during model training. This datagenerator handles the loading and processing of the data, including shuffling, standardization, and quantization of the data. It does by pre-processing the data and saving it as TFRecord files and then loading the batches on the fly during training.

"},{"location":"api/data_generator.html#methods","title":"Methods","text":""},{"location":"api/data_generator.html#__init__","title":"__init__(...)","text":"

Initialize the OptimizedDataGenerator class with the specified parameters to configure the data generator for preprocessing and batching.

"},{"location":"api/data_generator.html#arguments","title":"Arguments","text":"

Described in the comments of the __init__ method of the OptimizedDataGenerator.py file.

"},{"location":"api/data_generator.html#example-usage","title":"Example Usage","text":""},{"location":"api/data_generator.html#initializing-the-data-generators","title":"Initializing the Data Generators","text":"
training_generator = OptimizedDataGenerator(\n    data_directory_path = \"path/to/data/\",\n    labels_directory_path = \"path/to/labels/\",\n    is_directory_recursive = False,\n    file_type = \"parquet\",\n    data_format = \"3D\",\n    batch_size = val_batch_size,\n    file_count = val_file_size,\n    to_standardize= True,\n    include_y_local= False,\n    labels_list = ['x-midplane','y-midplane','cotAlpha','cotBeta'],\n    input_shape = (2,13,21), # (20,13,21),\n    transpose = (0,2,3,1),\n    shuffle = False, \n    files_from_end=True,\n\n    tfrecords_dir = \"path/to/tfrecords/\",\n    use_time_stamps = [0, 19], #-1\n    max_workers = 1, # Don't make this too large (will use up all RAM)\n    seed = 10, \n    quantize = True # Quantization ON\n)\n
"},{"location":"api/data_generator.html#loading-the-data-generators","title":"Loading the Data Generators","text":"

Already generated TFRecords can be reused by setting load_from_tfrecords_dir as

training_generator = OptimizedDataGenerator(\n    load_from_tfrecords_dir = \"path/to/tfrecords/\",\n    shuffle = True,\n    seed = 13,\n    quantize = True\n)\n

The same goes for the validation generator.

"},{"location":"api/data_generator.html#using-the-data-generators","title":"Using the Data Generators","text":"

The data generators can be directly passed to the fit method of a Keras model.

history = model.fit(\n                        x=training_generator,\n                        validation_data=validation_generator,\n                        #callbacks=[es, mcp, csv_logger],\n                        epochs=1000,\n                        shuffle=False,\n                        verbose=1\n )\n
"},{"location":"api/evaluate.html","title":"Evaluate Module","text":"

The evaluate.py file defines the evaluation function for the model.

"},{"location":"api/evaluate.html#functions-evaluateconfig","title":"Functions: evaluate(config)","text":""},{"location":"api/evaluate.html#example-usage","title":"Example Usage:","text":"
config = {\n    \"weightsPath\": \"path/to/weights.hdf5\",\n    \"outFileName\": \"path/to/evaluation_results.csv\",\n    \"data_directory_path\": \"path/to/data/\",\n    \"labels_directory_path\": \"path/to/labels/\",\n    \"n_filters\": 5,\n    \"pool_size\": 3,\n    \"val_batch_size\": 500,\n    \"val_file_size\": 10\n}\nevaluate(config)\n
"},{"location":"api/loss.html","title":"Loss Module","text":"

This module uses a Mixture Density Network(MDN) and hence a negative log-likelihood loss function. It uses TensorFlow and TensorFlow Probability for the loss computation.

"},{"location":"api/loss.html#loss-function","title":"Loss Function","text":""},{"location":"api/loss.html#custom_lossy-p_base-minval1e-9-maxval1e9-scale512","title":"custom_loss(y, p_base, minval=1e-9, maxval=1e9, scale=512)","text":"

Calculates the Negative Log-Likelihood (NLL) for a batch of data using the model's predicted parameters.

"},{"location":"api/loss.html#brief-description","title":"Brief Description","text":"

The model parameters are the mean and the lower triangular part of the covariance matrix.

loss function is vectorized with batches.

"},{"location":"api/loss.html#arguments","title":"Arguments","text":""},{"location":"api/loss.html#returns","title":"Returns","text":""},{"location":"api/loss.html#example-usage","title":"Example Usage","text":"
import tensorflow as tf\nfrom tensorflow.keras.optimizers import Adam\nfrom loss import custom_loss\nfrom models import CreateModel\n\nmodel = CreateModel((13, 21, 2), n_filters=5, pool_size=3)\nmodel.compile(optimizer=Adam(learning_rate=0.001), loss=custom_loss)\n
"},{"location":"api/models.html","title":"Models Module","text":"

The models.py file defines Mixture Density Network (MDN) network with a 4D Multivariate Normal Distribution neural network architecture using quantized layers. The implementation uses QKeras to quantize the weights and activations of the network.

"},{"location":"api/models.html#functions","title":"Functions","text":""},{"location":"api/models.html#createmodelshape-n_filters-pool_size","title":"CreateModel(shape, n_filters, pool_size)","text":"

Creates a quantized neural network model for regression task with quantized layers and activations as in Model. The model has 14 output nodes with 4 being the target variables and the rest 10 being the co-variances.

model = CreateModel((13, 21, 2), n_filters=5, pool_size=3) model.summary()

"},{"location":"api/models.html#additional-helper-functions","title":"Additional Helper Functions","text":""},{"location":"api/models.html#conv_networkvar-n_filters5-kernel_size3","title":"conv_network(var, n_filters=5, kernel_size=3)","text":"

Defines the convolutional network block, with quantized layers and activations.

"},{"location":"api/models.html#var_networkvar-hidden10-output2","title":"var_network(var, hidden=10, output=2)","text":"

Defines the dense network block, with quantized layers and activations.

"},{"location":"api/plotting.html","title":"Plot Module","text":"

Add Plot results here

"},{"location":"api/utils.html","title":"Utils Module","text":"

This module contains utility functions to manage file operations and GPU configurations.

"},{"location":"api/utils.html#functions","title":"Functions","text":""},{"location":"api/utils.html#safe_remove_directorydirectory_path","title":"safe_remove_directory(directory_path)","text":"

Safely removes a directory if it exists.

"},{"location":"api/utils.html#check_gpu","title":"check_GPU()","text":"

Checks for available GPUs and sets memory growth to prevent allocation issues.

"}]} \ No newline at end of file diff --git a/docs/sitemap.xml b/docs/sitemap.xml index 42fc568..49640e5 100644 --- a/docs/sitemap.xml +++ b/docs/sitemap.xml @@ -2,42 +2,42 @@ https://smart-pix.github.io/documentation/index.html - 2025-01-10 + 2025-01-13 https://smart-pix.github.io/documentation/plot.html - 2025-01-10 + 2025-01-13 https://smart-pix.github.io/documentation/testing.html - 2025-01-10 + 2025-01-13 https://smart-pix.github.io/documentation/usage.html - 2025-01-10 + 2025-01-13 https://smart-pix.github.io/documentation/api/data_generator.html - 2025-01-10 + 2025-01-13 https://smart-pix.github.io/documentation/api/evaluate.html - 2025-01-10 + 2025-01-13 https://smart-pix.github.io/documentation/api/loss.html - 2025-01-10 + 2025-01-13 https://smart-pix.github.io/documentation/api/models.html - 2025-01-10 + 2025-01-13 https://smart-pix.github.io/documentation/api/plotting.html - 2025-01-10 + 2025-01-13 https://smart-pix.github.io/documentation/api/utils.html - 2025-01-10 + 2025-01-13 \ No newline at end of file diff --git a/docs/sitemap.xml.gz b/docs/sitemap.xml.gz index 34cd98e..7fbdd0d 100644 Binary files a/docs/sitemap.xml.gz and b/docs/sitemap.xml.gz differ diff --git a/src/README.md b/src/README.md index 10a4580..6729f20 100644 --- a/src/README.md +++ b/src/README.md @@ -103,21 +103,82 @@ model.summary() ``` This generates a model with the following architecture: -| Type | Output Shape | Parameters | -|----------------------|---------------------|------------| -| InputLayer | `(None, 13, 21, 2)`| 0 | -| QSeparableConv2D | `(None, 11, 19, 5)`| 33 | -| QActivation | `(None, 11, 19, 5)`| 0 | -| QConv2D | `(None, 11, 19, 5)`| 30 | -| QActivation | `(None, 11, 19, 5)`| 0 | -| AveragePooling2D | `(None, 3, 6, 5)` | 0 | -| QActivation | `(None, 3, 6, 5)` | 0 | -| Flatten | `(None, 90)` | 0 | -| QDense | `(None, 16)` | 1456 | -| QActivation | `(None, 16)` | 0 | -| QDense | `(None, 16)` | 272 | -| QActivation | `(None, 16)` | 0 | -| QDense | `(None, 14)` | 238 | + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
TypeOutput ShapeParameters
InputLayer(None, 13, 21, 2)0
QSeparableConv2D(None, 11, 19, 5)33
QActivation(None, 11, 19, 5)0
QConv2D(None, 11, 19, 5)30
QActivation(None, 11, 19, 5)0
AveragePooling2D(None, 3, 6, 5)0
QActivation(None, 3, 6, 5)0
Flatten(None, 90)0
QDense(None, 16)1456
QActivation(None, 16)0
QDense(None, 16)272
QActivation(None, 16)0
QDense(None, 14)238
## Model Evaluation Refer to [Evaluate](api/evaluate.md) for more details