> For the complete documentation index, see [llms.txt](https://amobile-solutions.gitbook.io/yocto-developer-guide/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://amobile-solutions.gitbook.io/yocto-developer-guide/test-and-use-the-interface/nnstreamer.md).

# NNStreamer

{% hint style="info" %}
For more details, please visit the official MediaTek IoT Yocto [NNStreamer page](https://mediatek.gitlab.io/aiot/doc/aiot-dev-guide/master/tools/nnstreamer.html).
{% endhint %}

{% hint style="info" %}
The following instructions utilize the SD510 for demonstration purposes. These procedures are applicable to other development boards.
{% endhint %}

## NNStreamer Unit Test

NNStreamer offers a [gtest-based test suite](https://github.com/nnstreamer/nnstreamer/tree/main/tests) for both its common library and plugins. To assess NNStreamer's integration status on IoT Yocto, execute the unit tests with the following command.

```sh
cd /usr/bin/unittest-nnstreamer/
ssat
```

Here takes ArmNN unit test as an example.

```sh
cd /usr/bin/unittest-nnstreamer/tests/
export NNSTREAMER_SOURCE_ROOT_PATH=/usr/bin/unittest-nnstreamer/
./unittest_filter_armnn
```

## NNStreamer Examples

Explore the Python examples available in `/usr/bin/nnstreamer-demo/` on IoT Yocto to learn how to build NNStreamer pipelines with varied `tensor_filters` configurations for different applications. These examples are adapted from the [NNStreamer-Example](https://github.com/nnstreamer/nnstreamer-example) repository.

| Category                   | Input Source |
| -------------------------- | ------------ |
| Image Classification       | Camera       |
| Object Detection           | Camera       |
| Object Detection           | Camera       |
| Pose Estimation            | Camera       |
| Face Detection             | Camera       |
| Monocular Depth Estimation | Camera       |
| Image Enhancement          | Image        |

### General Configuration

{% hint style="info" %}
The SBC-MB510 MIPI-CSI camera is still in development. Please use a device with UVC camera functionality to run the following example.
{% endhint %}

#### Get camera node ID

To obtain the correct **camera node ID** with the following command:

```sh
v4l2-ctl --list-devices
```

We've provided the following example:

```
root@sd510:~# v4l2-ctl --list-devices
...
Integrated Camera: Integrated C (usb-11200000.xhci1-1.2):
        /dev/video5
        /dev/video6
        /dev/media1
...
```

In this case, the camera node ID is <mark style="color:red;">**5**</mark> and Type is <mark style="color:red;">**uvc**</mark>

### Demo Runner

Usage

```
usage: run_nnstreamer_example.py [-h] [--app {image_classification,object_detection,object_detection_yolov5,face_detection,pose_estimation,low_light_image_enhancement,monocular_depth_estimation}]
                                 [--engine {neuronsdk,tflite,armnn}] [--img IMG] [--cam CAM] --cam_type {uvc,yuvsensor,rawsensor} [--width WIDTH] [--height HEIGHT] [--performance {0,1}] [--fullscreen {0,1}] [--throughput {0,1}]
                                 [--rot ROT]

options:
  -h, --help            show this help message and exit
  --app {image_classification,object_detection,object_detection_yolov5,face_detection,pose_estimation,low_light_image_enhancement,monocular_depth_estimation}
                        Choose a demo app to run. Default: image_classification
  --engine {neuronsdk,tflite,armnn}
                        Choose a backends to inference. Default: neuronsdk
  --img IMG             Input a image file path.
                        Example: /usr/bin/nnstreamer-demo/original.png
                        Note: This paramater is dedicated to low light enhancement app
  --cam CAM             Input a camera node id, ex: 130 .
                        Use 'v4l2-ctl --list-devices' query camera node id.
                        Example:
                        $ v4l2-ctl --list-devices
                          ...
                           C922 Pro Stream Webcam (usb-11290000.xhci-1.2):
                           /dev/video130
                           /dev/video131
                          ...
                        Note: This paramater is for all the apps except low light enhancement app.
  --cam_type {uvc,yuvsensor,rawsensor}
                        Choose correct type of camera being used for the demo, ex: yuvsensor
                        Note: This paramater is for all the apps except low light enhancement app.
  --width WIDTH         Input video display width, ex: 640
  --height HEIGHT       Input video display height, ex: 480
  --performance {0,1}   Enable to make CPU/GPU/APU run under performance mode, ex: 1
  --fullscreen {0,1}    Fullscreen preview.
                        1: Enable
                        0: Disable
                        Note: This paramater is for all the apps except low light enhancement app and monocular depth estimation app.
  --throughput {0,1}    Print throughput information.
                        1: Enable
                        0: Disable
  --rot ROT             Rotate the camera image by degrees, ex: 90
                        Note: This paramater is for all the apps except low light enhancement app.

```

### Examples

{% hint style="info" %}
The following example engine is neuronsdk and performance mode is enabled. \
For other engines and parameters, please refer to the official website.
{% endhint %}

#### Image Classification

Example command:

```
root@sd510:/usr/bin/nnstreamer-demo# python3 run_nnstreamer_example.py --app image_classification --engine neuronsdk --cam 5 --cam_type uvc --performance 1 --fullscreen 1
 --app image_classification --engine neuronsdk --cam 5 --cam_type uvc --performance 1 --fullscreen 1
INFO:root:finished to load labels, total [1001]
INFO:root:Set performance mode
INFO:root:pipeline: v4l2src name=src device=/dev/video5 io-mode=mmap ! video/x-raw,width=640,height=480,format=YUY2 ! tee name=t_raw t_raw. ! queue leaky=2 max-size-buffers=10 ! textoverlay name=label font-desc=Sans,18 valignment=top ! fpsdisplaysink name=sink text-overlay=false signal-fps-measurements=true sync=false video-sink="waylandsink sync=false qos=false fullscreen=1"t_raw. ! queue leaky=2 max-size-buffers=2 ! videoconvert ! videoscale ! video/x-raw,width=224,height=224,format=RGB ! tensor_converter ! tensor_filter framework=neuronsdk throughput=0 name=nn model=/usr/bin/nnstreamer-demo/mobilenet_v1_1.0_224_quant.dla inputtype=uint8 input=3:224:224:1 outputtype=uint8 output=1001:1 ! tensor_sink name=tensor_sink
INFO:root:Run: Image classification.
INFO:root:received start message
```

<figure><img src="https://3619554908-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmAO6HInc2Typbuq3W42l%2Fuploads%2FurirSMqrTBIMf8ueC0ZH%2Fwayland-screenshot-2025-02-19_09-51-30.png?alt=media&amp;token=b27ba3d7-5d63-4856-85a1-d220274026d9" alt=""><figcaption><p>Image Classification</p></figcaption></figure>

#### Object Detection

Example command:

```
root@sd510:/usr/bin/nnstreamer-demo# python3 run_nnstreamer_example.py --app object_detection --engine neuronsdk --cam 5 --cam_type uvc --performance 1 --fullscreen 1
 --app object_detection --engine neuronsdk --cam 5 --cam_type uvc --performance 1 --fullscreen 1
INFO:root:Set performance mode
INFO:root:pipeline: v4l2src name=src device=/dev/video5 io-mode=mmap ! video/x-raw,width=640,height=480,format=YUY2 ! tee name=t_raw t_raw. ! queue leaky=2 max-size-buffers=10 ! compositor name=mix sink_0::zorder=1 sink_1::zorder=2 latency=999999999 ! fpsdisplaysink name=sink text-overlay=false signal-fps-measurements=true sync=false video-sink="waylandsink sync=false qos=false fullscreen=1"t_raw. ! queue leaky=2 max-size-buffers=2 ! videoconvert ! videoscale ! video/x-raw,width=300,height=300,format=RGB ! tensor_converter ! tensor_transform mode=arithmetic option=typecast:float32,add:-127.5,div:127.5 ! tensor_filter framework=neuronsdk throughput=0 name=nn model=/usr/bin/nnstreamer-demo/ssd_mobilenet_v2_coco.dla inputtype=float32 input=3:300:300:1 outputtype=float32,float32 output=4:1:1917:1,91:1917:1 ! tensor_decoder mode=bounding_boxes option1=mobilenet-ssd option2=/usr/bin/nnstreamer-demo/coco_labels_list.txt option3=/usr/bin/nnstreamer-demo/box_priors.txt option4=640:480 option5=300:300 ! mix.
INFO:root:Run: Object detection.
INFO:root:received start message
INFO:root:[qos] format[None] processed[18446744073709551615] dropped[18446744073709551615]
INFO:root:[qos] format[None] processed[18446744073709551615] dropped[18446744073709551615]
```

<figure><img src="https://3619554908-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmAO6HInc2Typbuq3W42l%2Fuploads%2FSFpJ6zSgbFCUPRjonG6N%2Fwayland-screenshot-2025-02-19_09-59-03.png?alt=media&amp;token=af9b52e3-040a-4313-b4a5-e0a020db7bcb" alt=""><figcaption><p>Object Detection</p></figcaption></figure>

#### Object Detection (YOLO\_V5)

Example command:

```
root@sd510:/usr/bin/nnstreamer-demo# python3 run_nnstreamer_example.py --app object_detection_yolov5 --engine neuronsdk --cam 5 --cam_type uvc --performance 1 --fullscreen 1
 --app object_detection_yolov5 --engine neuronsdk --cam 5 --cam_type uvc --performance 1 --fullscreen 1
INFO:root:Set performance mode
INFO:root:pipeline: v4l2src name=src device=/dev/video5 io-mode=mmap ! video/x-raw,width=640,height=480,format=YUY2 ! tee name=t_raw t_raw. ! queue leaky=2 max-size-buffers=10 ! compositor name=mix sink_0::zorder=1 sink_1::zorder=2 latency=999999999 ! fpsdisplaysink name=sink text-overlay=false signal-fps-measurements=true sync=false video-sink="waylandsink sync=false qos=false fullscreen=1"t_raw. ! queue leaky=2 max-size-buffers=2 ! videoconvert ! videoscale ! video/x-raw,width=320,height=320,format=RGB ! tensor_converter ! tensor_filter framework=neuronsdk throughput=0 name=nn model=/usr/bin/nnstreamer-demo/yolov5s-int8.dla inputtype=uint8 input=3:320:320:1 outputtype=uint8 output=85:6300:1 ! other/tensors,num_tensors=1,types=uint8,dimensions=85:6300:1:1,format=static ! tensor_transform mode=arithmetic option=typecast:float32,add:-4.0,mul:0.0051498096 ! tensor_decoder mode=bounding_boxes option1=yolov5 option2=/usr/bin/nnstreamer-demo/coco.txt option3=0 option4=640:480 option5=320:320 ! mix.
INFO:root:Run: Object detection.
INFO:root:received start message
INFO:root:[qos] format[None] processed[18446744073709551615] dropped[18446744073709551615]
INFO:root:[qos] format[None] processed[18446744073709551615] dropped[18446744073709551615]

```

<figure><img src="https://3619554908-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmAO6HInc2Typbuq3W42l%2Fuploads%2FENMBLAwZWnLOetHBATjq%2Fwayland-screenshot-2025-02-19_10-02-47.png?alt=media&amp;token=61f0227d-d6a6-442e-af9f-8200122bce5f" alt=""><figcaption><p>Object Detection (YOLO_V5)</p></figcaption></figure>

#### Pose Estimation

Example command:

```
root@sd510:/usr/bin/nnstreamer-demo# python3 run_nnstreamer_example.py --app pose_estimation --engine neuronsdk --cam 5 --cam_type uvc --performance 1 --fullscreen 1
 --app pose_estimation --engine neuronsdk --cam 5 --cam_type uvc --performance 1 --fullscreen 1
INFO:root:Set performance mode
INFO:root:pipeline: v4l2src name=src device=/dev/video5 io-mode=mmap ! video/x-raw,width=640,height=480,format=YUY2 ! tee name=t_raw t_raw. ! queue leaky=2 max-size-buffers=10 ! compositor name=mix sink_0::zorder=1 sink_1::zorder=2 latency=999999999 ! fpsdisplaysink name=sink text-overlay=false signal-fps-measurements=true sync=false video-sink="waylandsink sync=false qos=false fullscreen=1"t_raw. ! queue leaky=2 max-size-buffers=2 ! videoconvert ! videoscale ! video/x-raw,width=257,height=257,format=RGB ! tensor_converter ! tensor_transform mode=arithmetic option=typecast:float32,add:-127.5,div:127.5 ! tensor_filter framework=neuronsdk throughput=0 name=nn model=/usr/bin/nnstreamer-demo/posenet_mobilenet_v1_100_257x257_multi_kpt_stripped.dla inputtype=float32 input=3:257:257:1 outputtype=float32,float32,float32,float32 output=17:9:9:1,34:9:9:1,32:9:9:1,32:9:9:1 ! tensor_decoder mode=pose_estimation option1=640:480 option2=257:257 option3=/usr/bin/nnstreamer-demo/point_labels.txt option4=heatmap-offset ! mix.
INFO:root:Run: Pose estimation.
INFO:root:received start message
INFO:root:[qos] format[None] processed[18446744073709551615] dropped[18446744073709551615]
```

<figure><img src="https://3619554908-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmAO6HInc2Typbuq3W42l%2Fuploads%2FyrczdYyKOMvRIRK8ahk2%2Fwayland-screenshot-2025-02-19_10-08-01.png?alt=media&amp;token=318267dd-dd16-48c3-a9b3-c3fc44a90a9f" alt=""><figcaption><p>Pose Estimation</p></figcaption></figure>

#### Face Detection

Example command:

```
root@sd510:/usr/bin/nnstreamer-demo# python3 run_nnstreamer_example.py --app face_detection --engine neuronsdk --cam 5 --cam_type uvc --performance 1 --fullscreen 1
 --app face_detection --engine neuronsdk --cam 5 --cam_type uvc --performance 1 --fullscreen 1
INFO:root:Set performance mode
INFO:root:pipeline: v4l2src name=src device=/dev/video5 io-mode=mmap ! video/x-raw,width=640,height=480,format=YUY2 ! tee name=t_raw t_raw. ! queue leaky=2 max-size-buffers=10 ! videoconvert ! cairooverlay name=tensor_res ! fpsdisplaysink name=sink text-overlay=false signal-fps-measurements=true sync=false video-sink="waylandsink sync=false qos=false fullscreen=1"t_raw. ! queue leaky=2 max-size-buffers=2 ! videoconvert ! videoscale ! video/x-raw,width=300,height=300,format=RGB ! tensor_converter ! tensor_transform mode=arithmetic option=typecast:float32,add:-127.5,div:127.5 ! tensor_filter framework=neuronsdk throughput=0 name=nn model=/usr/bin/nnstreamer-demo/detect_face.dla inputtype=float32 input=3:300:300:1 outputtype=float32,float32 output=4:1:1917:1,2:1917:1 ! tensor_sink name=res_face
INFO:root:Run: Face detection.
INFO:root:received start message
INFO:root:[qos] format[None] processed[18446744073709551615] dropped[18446744073709551615]

```

<figure><img src="https://3619554908-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmAO6HInc2Typbuq3W42l%2Fuploads%2FVf2AM9eKg7REEfofzoR8%2Fwayland-screenshot-2025-02-19_10-12-18.png?alt=media&amp;token=c99a42c3-2d43-4262-be5b-004a4d72703f" alt=""><figcaption><p>Face Detection</p></figcaption></figure>

#### Monocular Depth Estimation

Example command:

```
root@sd510:/usr/bin/nnstreamer-demo# python3 run_nnstreamer_example.py --app monocular_depth_estimation --engine neuronsdk --cam 5 --cam_type uvc --performance 1 --fullscreen 1
 --app monocular_depth_estimation --engine neuronsdk --cam 5 --cam_type uvc --performance 1 --fullscreen 1
INFO:root:Set performance mode
INFO:root:Pipeline: v4l2src name=src device=/dev/video5 ! video/x-raw,format=YUY2,width=640,height=480,framerate=30/1 ! videoconvert ! videoscale ! video/x-raw,format=RGB,width=256,height=256 ! tensor_converter ! tensor_transform mode=arithmetic option=typecast:float32,add:-127.5,div:127.5 ! tensor_filter framework=neuronsdk throughput=0 model=/usr/bin/nnstreamer-demo/midas.dla inputtype=float32 input=3:256:256:1 outputtype=float32 output=1:256:256:1 ! appsink name=sink emit-signals=True max-buffers=1 drop=True sync=False
INFO:root:Running MiDaS model for depth estimation
```

<figure><img src="https://3619554908-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmAO6HInc2Typbuq3W42l%2Fuploads%2F57939DyTYv92IQyM4KEe%2Fimage.png?alt=media&amp;token=f24279bd-5556-4363-8ccf-a7cb70ec2161" alt=""><figcaption><p>Monocular Depth Estimation</p></figcaption></figure>

#### Image Enhancement

Example command:

```
root@sd510:/usr/bin/nnstreamer-demo# python3 run_nnstreamer_example.py --app low_light_image_enhancement --engine neuronsdk --img /home/root/nn_ss/low_light.png --cam_type uvc --width 600 --height 400 --performance 1
 --app low_light_image_enhancement --engine neuronsdk --img /home/root/nn_ss/low_light.png --cam_type uvc --width 600 --height 400 --performance 1
INFO:root:Set performance mode
INFO:root:pipeline: filesrc location=/home/root/nn_ss/low_light.png ! pngdec ! imagefreeze num-buffers=2 ! videoscale ! videoconvert ! video/x-raw,width=600,height=400,format=RGB ! tensor_converter ! tensor_transform mode=arithmetic option=typecast:float32,add:0,div:255.0 ! tensor_filter framework=neuronsdk throughput=1 name=nn model=/usr/bin/nnstreamer-demo/lite-model_zero-dce_1.dla inputtype=float32 input=3:600:400:1 outputtype=float32 output=3:600:400:1 ! tensor_sink name=tensor_sink
INFO:root:Run: Low light image enhancement.
INFO:root:received start message
INFO:root:export png file: ./test_neuronsdk.png
INFO:root:[on_buffer] time[85.164367] ms
INFO:root:export png file: ./test_neuronsdk.png
INFO:root:received eos message

```

<div><figure><img src="https://3619554908-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmAO6HInc2Typbuq3W42l%2Fuploads%2FmYi6WgQHC7bxFJZux2kD%2Flow_light.png?alt=media&amp;token=f91ecbaf-16ad-45c7-bb96-9ec8b0e07226" alt="" width="480"><figcaption><p>Low-light Picture</p></figcaption></figure> <figure><img src="https://3619554908-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmAO6HInc2Typbuq3W42l%2Fuploads%2Fn2vTMCR74dftprJzGhBq%2Ftest_neuronsdk.png?alt=media&amp;token=bc4453a8-993c-4c37-ad94-ed58f7138664" alt="" width="450"><figcaption><p>Enhancement Picture</p></figcaption></figure></div>
