1. What is NanoEdge AI Library?
NanoEdge™ AI Library is an Artificial Intelligence (AI) static library for embedded C software running on Arm® Cortex® microcontrollers.
When embedded on microcontrollers, it gives them the ability to easily detect anomalies, identify outliers, classify sensor patterns or extrapolate numerical values, by themselves, without the need for the user to have additional skills in Mathematics, Machine Learning, or data science.
The type of library depends on the project created in NanoEdge AI Studio (also called the Studio):
- Anomaly detection (AD): detects abnormal behavior compared to learned nominal patterns.
- 1-class classification (1CC, outlier detection): identifies if a signal is inside the class or outside the class (outlier).
- n-class classification (nCC): classifies a signal among several classes.
- Extrapolation (E, regression): estimates a numerical value from a signal.
2. Purpose of NanoEdge AI Emulator
With NanoEdge AI Emulator, you can emulate the behavior of your NanoEdge AI Library, from the command line or from Python code, and start testing it as if it was running on your embedded application.
The emulator is a single Python script, nanoedgeai_studio_emulator.py, common to all project types. It loads the compiled library (libneai.dll on Windows®, libneai.so on Linux®) provided with each project created by the Studio, and automatically detects the type of model it contains. This means that for one library, the emulator uses exactly the same algorithm.
Requirements:
- Python 3.7 or higher (standard library only, no additional package needed).
- The compiled NanoEdge AI library (
libneai.dllorlibneai.so).
By default, the script looks for the library in its own directory. Otherwise, specify its location with --lib.
3. NanoEdge AI Emulator functions
3.1. Command line usage
python nanoedgeai_studio_emulator.py [--lib LIB] [--learn LEARN_FILE] [--detect DETECT_FILE] [--ad_use_embedded_knowledge] [-v]
Arguments:
--lib: (optional) path to the library file (libneai.dllorlibneai.so). Auto-detected in the script directory if not provided.--learn: path to the CSV file containing the signals to learn (anomaly detection only).--detect: path to the CSV file containing the signals for inference.--ad_use_embedded_knowledge: for anomaly detection models, initialize the model with the embedded knowledge. Ignored for other model types.-v,--verbose: display the result of each signal.
If neither --learn nor --detect is provided, the help is displayed.
3.2. Learning (anomaly detection only)
Usage:
python nanoedgeai_studio_emulator.py --lib libneai.so --learn learn_file.csv
Each line of the file is learned as one signal. Learning is complete when the library returns NEAI_LEARNING_DONE.
Response:
NanoEdgeAI Studio Emulator - Python interface for NanoEdgeAI libraries - Copyright (c) 2025 STMicroelectronics
Detected algorithm type: Anomaly Detection
Learning from: learn_file.csv
Learning complete! (100 signals)
3.3. Detection (inference)
Usage:
python nanoedgeai_studio_emulator.py --lib libneai.so --detect detect_file.csv
Learning and detection can be chained in the same call:
python nanoedgeai_studio_emulator.py --lib libneai.so --learn learn_file.csv --detect detect_file.csv -v
The output depends on the model type.
3.3.1. Anomaly detection
The result is a similarity score (0-100). A signal is considered nominal if its similarity is greater than or equal to 90, otherwise it is an anomaly.
Detection results (3 signals):
Signal 1: Similarity 98% - Nominal
Signal 2: Similarity 92% - Nominal
Signal 3: Similarity 41% - Anomaly
Detection summary (3 signals):
Nominal: 2 signals
Anomaly: 1 signals
3.3.2. 1-class classification (outlier detection)
Each signal is either inside the class (nominal) or outside the class (outlier).
Detection summary (5 signals):
Nominal: 4 signals
Outlier: 1 signals
3.3.3. n-class classification
Each signal is assigned to a class (name and identifier).
Detection results (3 signals):
Signal 1: class_2 (Class ID 1)
Probabilities: class_1: 0.0100, class_2: 0.9600, class_3: 0.0300
Signal 2: class_1 (Class ID 0)
Probabilities: class_1: 0.9000, class_2: 0.0500, class_3: 0.0500
Signal 3: class_2 (Class ID 1)
Probabilities: class_1: 0.1000, class_2: 0.8000, class_3: 0.1000
Detection summary (3 signals):
class_1: 1 signals
class_2: 2 signals
3.3.4. Extrapolation
The predicted value is always displayed for each signal, with or without -v (no summary). For multi-target models, a list of values is displayed. Values are float32 results converted to Python floats, so they may show more decimals than expected.
Detection results (2 signals):
Signal 1: 43.2
Signal 2: 12.7
3.3.5. Remarks
- Without
-v, only the detection summary is displayed (except for extrapolation). - If a signal cannot be processed,
Signal N: Error - <STATE>is displayed, and the number of errors is reported at the end. - The number of values of each line must equal the signal size multiplied by the number of axes expected by the library, otherwise an error is raised.
3.4. Input file format
The CSV file contains one signal per line. The separator (, or ; or | or a single space or a single tab) is detected automatically. Empty lines are ignored.
1.23 4.56 7.89 10.11
2.34 5.67 8.90 11.22
3.5. Python API
The emulator can also be used from Python code:
from nanoedgeai_studio_emulator import NanoEdgeAIEmulator, read_csv_data, NeaiState
with NanoEdgeAIEmulator('libneai.so') as emulator:
print(emulator.model_type) # anomaly_detection, classification, outlier_detection, extrapolation
if emulator.model_type == 'anomaly_detection':
emulator.learn_lines(read_csv_data('learn_file.csv'))
for result in emulator.detect_lines(read_csv_data('detect_file.csv')):
if result.state == NeaiState.NEAI_OK:
print(result.value, result.class_name, result.ad_is_nominal)
Main elements:
NanoEdgeAIEmulator(lib_path=None, ad_use_embedded_knowledge=False): loads the library and detects the model type. Use it as a context manager.learn(signal)/learn_lines(signals): learning (anomaly detection only).detect(signal)/detect_lines(signals): inference, returns aDetectionResult(or a list of them).DetectionResult:state(NeaiState),value(similarity, class id, outlier flag or predicted value),class_nameandclass_proba(classification: name and probability vector) andad_is_nominal(anomaly detection).model_type,class_number,class_names,target_number,input_signal_size,axis_number,data_length: information about the model.read_csv_data(path, drop_first_column=False): reads a CSV file as a list of signals.
Status codes (NeaiState): NEAI_OK (0), NEAI_ERROR (1), NEAI_NOT_INITIALIZED (2), NEAI_INVALID_PARAM (3), NEAI_NOT_SUPPORTED (4), NEAI_LEARNING_DONE (5), NEAI_LEARNING_IN_PROGRESS (6).
4. Resources
Documentation
All NanoEdge AI Studio documentation is available here.
Tutorials
Step-by-step tutorials to use NanoEdge AI Studio to build a smart device from A to Z.