> For the complete documentation index, see [llms.txt](https://lensai.gitbook.io/lens-ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lensai.gitbook.io/lens-ai/fundamentals/getting-started/step-2-integrating-lens-ai-cpp-profiler-on-edge.md).

# Step 2: Integrating Lens AI Cpp Profiler on Edge

{% hint style="info" %}
The current version of the Lens AI supports vision data in the next releases supports audio , timeseries and text data.
{% endhint %}

Lens AI Cpp profiler should be integrated on the edge device, where the inference happens.

<figure><img src="https://1293874244-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FaBxpe4kLU8KyHMlQtPS1%2Fuploads%2Fv9cD7jFna4uWK1wQ13E1%2Flensai_profiler_cpp.png?alt=media&amp;token=d21fede3-8c52-492a-af48-fe3230a4690b" alt=""><figcaption><p>Lens AI Cpp Profiler</p></figcaption></figure>

Build & Install the Cpp library on the device there are also prebuilt packages for Ubuntu x64-86 and  Arm architectures.&#x20;

```bash
https://github.com/lens-ai/lensai_profiler_cpp.git 
cd lensai_profiler_cpp 
mkdir build
cmake .. -D CMAKE_BUILD_TYPE=RELEASE
make install
ldconfig
```

```
There are also pre-built ubuntu docker images available on docker hub.
```

* docker pull vsnm/lensai\_profiler\_cpp:latest
* docker run -it --rm vsnm/lensai\_profiler\_cpp

Once the library is built and successfully installed then integrate the profiling code in your inference script

Define the configuration file based on the output from the previous step of computing the thresholds.

<table><thead><tr><th width="180">Metric </th><th></th><th>Description</th></tr></thead><tbody><tr><td>sampling</td><td></td><td>Sampling data where model  is most uncertain.</td></tr><tr><td></td><td>MARGINCONFIDENCE</td><td>Margin Confidence of the classes are above the threshold then sample those data points</td></tr><tr><td></td><td>LEASTCONFIDENCE</td><td>Least Confidence of the classes are above the threshold then sam</td></tr><tr><td></td><td>RATIOCONFIDENCE</td><td>Ratio Confidence of the classes are above the threshold then sam</td></tr><tr><td></td><td>FILEPATH</td><td>Path in which to save the metrics and samples</td></tr><tr><td>Image</td><td></td><td>Image related metrics. </td></tr><tr><td></td><td>NOISE</td><td></td></tr><tr><td></td><td>BRIGHTNESS</td><td></td></tr><tr><td></td><td>SHARPNESS</td><td></td></tr><tr><td></td><td>CHANNELS</td><td></td></tr><tr><td></td><td>HISTOGRAM</td><td></td></tr><tr><td></td><td>FILEPATH</td><td>Path to image related metrics and samples</td></tr><tr><td>model</td><td></td><td>Model Metrics.</td></tr><tr><td></td><td>FILEPATH</td><td>Path to the model related metrics and samples</td></tr></tbody></table>

```
Please keep all the metrics that need to be computed, 
if deleted the corresponding metrics are not computed, 
use NaN to disable sampling and just compute the metrics. 
```

```ini
[sampling] 
MARGINCONFIDENCE = 0.01, 0.9 
LEASTCONFIDENCE = 0.01, 0.9
RATIOCONFIDENCE = 0.01, 0.9 
ENTROPYCONFIDENCE = 0.01, 0.9 
filepath = /tmp/samples/ 
[image] 
CHANNELS = 3 
NOISE = 3, 14 
BRIGHTNESS = 23, 255 
SHARPNESS = 30, 255 
MEAN = NaN 
HISTOGRAM = NaN 
filepath = /tmp/imgstats/ 
[model] 
filepath = /tmp/modelstats/  
```

The  metrics always a lower and upper threshold is defined to capture the samples at the tails of the distribution. default values for the confidence are 0.01 and 0.9 meaning it samples the images that model is 99.9 % confident or above **or** below 10 % confident.&#x20;

define the frequency at which you want to save the metrics

```cpp
int saveIntervalSec = 1; 
int img_channels = 3; // Number of Channels
```

```cpp
  std::string modelName = "Cat_dog_classfier_0.1";

  ImageProfile image_profile(configFile, saveIntervalSec, channels);
  ModelProfile model_profile(modelName, configFile, saveIntervalSec, channels);
  ImageSampler image_sampler(configFile, saveIntervalSec);
```

In the inference part after the inference, you can ass the following line to start profiling

```cpp
std::cout << "profiling image profile" <<std::endl;
image_profile.profile(frame, true);
 
std::cout << "profiling model profile" << std::endl;
model_profile.log_classification_model_stats(10.0, top_results);
    
std::cout << "profiling samper" << std::endl;
 image_sampler.sample(top_results, image, true);
```
