DepthAI Tutorials
DepthAI API References

ON THIS PAGE

  • Script NNData example
  • Demo
  • Setup
  • Source code
  • Pipeline

Script NNData example

This example shows how to create a NNData message inside the Script node and then send it to the host (where it gets printed to the console).

Demo

Command Line
1~/depthai-python/examples/Script$ python3 script_nndata_datatype.py
2    Names of layers: ['fp16', 'uint8']
3    NNData size: 13
4    FP16 values: [1.0, 1.2001953125, 3.900390625, 5.5]
5    UINT8 values: [6, 9, 4, 2, 0]

Setup

Please run the install script to download all required dependencies. Please note that this script must be ran from git context, so you have to download the depthai-python repository first and then run the script
Command Line
1git clone https://github.com/luxonis/depthai-python.git
2cd depthai-python/examples
3python3 install_requirements.py
For additional information, please follow the installation guide.

Source code

Python
C++

Python

Python
GitHub
1#!/usr/bin/env python3
2import depthai as dai
3import time
4
5# Start defining a pipeline
6pipeline = dai.Pipeline()
7
8# Script node
9script = pipeline.create(dai.node.Script)
10script.setScript("""
11    buf = NNData(150)
12    buf.setLayer("fp16", [1.0, 1.2, 3.9, 5.5])
13    buf.setLayer("uint8", [6, 9, 4, 2, 0])
14    node.warn("Names of layers: " + str(buf.getAllLayerNames()))
15    node.io['host'].send(buf)
16""")
17
18# XLinkOut
19xout = pipeline.create(dai.node.XLinkOut)
20xout.setStreamName('host')
21script.outputs['host'].link(xout.input)
22
23# Connect to device with pipeline
24with dai.Device(pipeline) as device:
25    device.setLogLevel(dai.LogLevel.WARN)
26    device.setLogOutputLevel(dai.LogLevel.WARN)
27
28    nndata = device.getOutputQueue("host").get()
29    time.sleep(0.5)
30
31    print(f"NNData size: {len(nndata.getData())}")
32    print("FP16 values:", nndata.getLayerFp16("fp16"))
33    print("UINT8 values:",nndata.getLayerUInt8("uint8"))

Pipeline

Need assistance?

Head over to Discussion Forum for technical support or any other questions you might have.