🗒️Step 1: Integrating Lens AI Python Profiler

Lens AI Python Profiler profiles the data during the training phase. Currently Lens AI support Vision image data, support for other datatypes will be added in the next releases. please refere to product roadmap here:

Python Profiler library support tensorflow based training, pytorch will be supported in the future releases.

pip install lensai-profiler==1.0.0

Import the profiler library it support the following metrics right now

  1. Brightness

  2. Sharpness

  3. Noise

  4. Channel Pixels Mean

  5. Channel Pixesl Distribution

# lensai profiler library
from lensai_profiler.metrics import process_batch
from lensai_profiler.sketches import Sketches

# Initialize Lens AI sketches
num_channels = 3  # Assuming RGB images
sketches = Sketches(num_channels)

# Apply map function in parallel to compute metrics
base_metrics = train_dataset.map(
    lambda images, labels: process_batch(images),
    num_parallel_calls=tf.data.AUTOTUNE
)

# Iterate through the dataset and update the KLL sketches in parallel
for brightness, sharpness, channel_mean, snr, channel_pixels in train_dataset:
    sketches.tf_update_sketches(brightness, sharpness, channel_mean, snr, channel_pixels)

Once the metrics are computed save the metrics using the KLL sketches in the binary format.

# Save the KLL sketches to a specified directory
save_path = '/content/sample_data/'
sketches.save_sketches(save_path)

At this stage the baselines metrics for the training data are computed.

This generates the .bin file.

Qunatile Threshold Query the Sketches

It is possible to sample the or notify when the realtime data is away from the center of distribution. to do this we need to compute the base line thrsholds .

The following method allows to compute the thresholds from the bins

sketches.compute_thresholds()

These Thresholds can be set in the Lens AI Cpp Profiler on the edge device config file.

For detailed implementation refer: https://colab.research.google.com/drive/1dRinwpZwvpsts2TDoT3xQg6xfJnupfXm?usp=sharing

Last updated