ON THIS PAGE

  • NeuralNetwork
  • How to place it
  • Inputs and Outputs
  • Passthrough mechanism
  • Usage
  • Examples of functionality
  • Reference

NeuralNetwork

This node runs neural inference on input data. Any OpenVINO neural networks can be run using this node, as long as the VPU supports all layers. This allows you to pick from 200+ pre-trained model from Open Model Zoo and DepthAI Model Zoo and directly run it on the OAK device.Neural network has to be in .blob format to be compatible with the VPU. Instructions on how to compile your neural network (NN) to .blob can be found here.

How to place it

Python
C++

Python

Python
1pipeline = dai.Pipeline()
2nn = pipeline.create(dai.node.NeuralNetwork)

Inputs and Outputs

Passthrough mechanism

The passthrough mechanism is very useful when a node specifies its input to be non-blocking, where messages can be overwritten. There we don't know on which message the node performed its operation (eg NN, was inference done on frame 25 or skipped 25 and performed inference on 26). At the same time means that if: xlink and host input queues are blocking, and we receive both say passthrough and output we can do a blocking get on both of those queues and be sure to always get matching frames. They might not arrive at the same time, but both of them will arrive, and be in queue in correct spot to be taken out together.

Usage

Python
C++

Python

Python
1pipeline = dai.Pipeline()
2nn = pipeline.create(dai.node.NeuralNetwork)
3nn.setBlobPath(bbBlobPath)
4cam.out.link(nn.input)
5
6# Send NN out to the host via XLink
7nnXout = pipeline.create(dai.node.XLinkOut)
8nnXout.setStreamName("nn")
9nn.out.link(nnXout.input)
10
11with dai.Device(pipeline) as device:
12  qNn = device.getOutputQueue("nn")
13
14  nnData = qNn.get() # Blocking
15
16  # NN can output from multiple layers. Print all layer names:
17  print(nnData.getAllLayerNames())
18
19  # Get layer named "Layer1_FP16" as FP16
20  layer1Data = nnData.getLayerFp16("Layer1_FP16")
21
22  # You can now decode the output of your NN

Examples of functionality

Reference

class

depthai.node.NeuralNetwork(depthai.Node)

method
getNumInferenceThreads(self) -> int: int
How many inference threads will be used to run the network  Returns:     Number of threads, 0, 1 or 2. Zero means AUTO
method
method
setBlobPath(self, path: Path)
Load network blob into assets and use once pipeline is started.  Throws:     Error if file doesn't exist or isn't a valid network blob.  Parameter ``path``:     Path to network blob
method
setNumInferenceThreads(self, numThreads: int)
How many threads should the node use to run the network.  Parameter ``numThreads``:     Number of threads to dedicate to this node
method
setNumNCEPerInferenceThread(self, numNCEPerThread: int)
How many Neural Compute Engines should a single thread use for inference  Parameter ``numNCEPerThread``:     Number of NCE per thread
method
setNumPoolFrames(self, numFrames: int)
Specifies how many frames will be available in the pool  Parameter ``numFrames``:     How many frames will pool have
property
input
Input message with data to be inferred upon Default queue is blocking with size 5
property
inputs
Inputs mapped to network inputs. Useful for inferring from separate data sources Default input is non-blocking with queue size 1 and waits for messages
property
out
Outputs NNData message that carries inference results
property
passthrough
Passthrough message on which the inference was performed.  Suitable for when input queue is set to non-blocking behavior.
property
passthroughs
Passthroughs which correspond to specified input

Need assistance?

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