Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/happyme531/ztu_somemodelruntime_ez_rknn_async/llms.txt

Use this file to discover all available pages before exploring further.

NodeArg describes a single input or output tensor of a loaded RKNN model. You obtain NodeArg instances by calling session.get_inputs() or session.get_outputs(). All properties are read-only; the objects are created by the runtime when the session is initialised and reflect the model’s compiled metadata.

Properties

name
str
The tensor name from the compiled model. For models where a tensor has no explicit name, the runtime synthesises one using the pattern "input_N" or "output_N" where N is the zero-based index.
node = session.get_inputs()[0]
print(node.name)  # 'images'
shape
List[int]
The tensor’s dimension sizes as a list of integers, in the order the model was compiled with. A 4-D image input compiled with NCHW layout will have shape = [batch, channels, height, width].
node = session.get_inputs()[0]
print(node.shape)  # [1, 3, 640, 640]
type
str
An ONNX-style data type string describing the element type of the tensor. The supported values and their corresponding NumPy dtypes are listed below.
type stringNumPy dtype
tensor(float)float32
tensor(float16)float16
tensor(int8)int8
tensor(uint8)uint8
tensor(int16)int16
tensor(uint16)uint16
tensor(int32)int32
tensor(uint32)uint32
tensor(int64)int64
tensor(bool)bool
node = session.get_inputs()[0]
print(node.type)  # 'tensor(float)'

Inspecting a model before inference

Reading the input and output descriptors before calling run helps you allocate correctly-typed arrays and verify that your pre-processing pipeline matches the model’s expectations.
import numpy as np
import ztu_somemodelruntime_ez_rknn_async as ez

session = ez.InferenceSession("model.rknn")

print("Inputs:")
for node in session.get_inputs():
    print(f"  {node.name}: shape={node.shape}, type={node.type}")

print("Outputs:")
for node in session.get_outputs():
    print(f"  {node.name}: shape={node.shape}, type={node.type}")
Example output for a YOLOv5s model:
Inputs:
  images: shape=[1, 3, 640, 640], type=tensor(float)
Outputs:
  output0: shape=[1, 25200, 85], type=tensor(float)

Building an input array from NodeArg

You can use the shape and type properties to allocate a correctly-typed placeholder array programmatically:
import numpy as np

DTYPE_MAP = {
    "tensor(float)":   np.float32,
    "tensor(float16)": np.float16,
    "tensor(int8)":    np.int8,
    "tensor(uint8)":   np.uint8,
    "tensor(int16)":   np.int16,
    "tensor(uint16)":  np.uint16,
    "tensor(int32)":   np.int32,
    "tensor(uint32)":  np.uint32,
    "tensor(int64)":   np.int64,
    "tensor(bool)":    np.bool_,
}

def make_zero_input(node):
    dtype = DTYPE_MAP[node.type]
    return np.zeros(node.shape, dtype=dtype)

inputs = {node.name: make_zero_input(node) for node in session.get_inputs()}
outputs = session.run(None, inputs)
Use session.input_names and session.output_names when you only need the tensor names and do not require shape or type information. Calling get_inputs() and get_outputs() is only necessary when you need the full NodeArg descriptor.

Build docs developers (and LLMs) love