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
2Names of layers: ['fp16', 'uint8']
3NNData size: 13
4FP16 values: [1.0, 1.2001953125, 3.900390625, 5.5]
5UINT8 values: [6, 9, 4, 2, 0]

Setup

This example requires the DepthAI v3 API, see installation instructions.

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.