DepthAI v2 has been superseded by DepthAI v3. You are viewing legacy documentation.
此页面由 AI 自动翻译。查看英文原版
最后更新

本页目录

  • 如何放置
  • 输入和输出
  • 直通机制
  • 用法
  • 功能示例
  • 参考
Claude CodeCodexCursor
Luxonis 智能体工具包为你常用的编程智能体加载 Luxonis 上下文与技能,更快地基于 OAK 开发应用。
安装工具包

NeuralNetwork

最后更新
此节点对输入数据执行神经网络推理。任何 OpenVINO 神经网络都可以使用此节点运行,只要 VPU 支持所有层。 这允许您从 Open Model Zoo 和 DepthAI Model Zoo 中选择 200 多个预训练模型,并直接在 OAK 设备上运行。神经网络必须是 .blob 格式才能与 VPU 兼容。有关如何将神经网络 (NN) 编译为 .blob 的说明,请参见此处。

如何放置

Python

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

C++

C++
1dai::Pipeline pipeline;
2auto nn = pipeline.create<dai::node.NeuralNetwork>();

输入和输出

直通机制

当节点将其输入指定为非阻塞时,直通机制非常有用,消息可以被覆盖。 我们不知道节点对哪个消息执行了操作(例如 NN,推理是在第 25 帧上完成还是跳过 25 并在 26 上执行)。同时,这意味着如果:xlink 和主机输入队列是阻塞的,并且我们同时接收到直通和输出,我们可以对这两个队列进行阻塞获取,并确保始终获得匹配的帧。它们可能不会同时到达,但它们都会到达,并按正确的顺序排队等待一起取出。

用法

Python

Python
1pipeline = dai.Pipeline()
2nn = pipeline.create(dai.node.NeuralNetwork)
3nn.setBlobPath(bbBlobPath)
4cam.out.link(nn.input)
5
6# 通过 XLink 将 NN 输出发送到主机
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() # 阻塞
15
16  # NN 可以从多个层输出。打印所有层名称:
17  print(nnData.getAllLayerNames())
18
19  # 获取名为 "Layer1_FP16" 的层作为 FP16
20  layer1Data = nnData.getLayerFp16("Layer1_FP16")
21
22  # 您现在可以解码 NN 的输出

C++

C++
1dai::Pipeline pipeline;
2auto nn = pipeline.create<dai::node.NeuralNetwork>();
3nn->setBlobPath(bbBlobPath);
4cam->out.link(nn->input);
5
6// 通过 XLink 将 NN 输出发送到主机
7auto nnXout = pipeline.create<dai::node.XLinkOut>();
8nnXout->setStreamName("nn");
9nn->out.link(nnXout->input);
10
11dai::Device device(pipeline);
12// 启动管道
13device.startPipeline();
14
15auto qNn = device.getOutputQueue("nn");
16
17auto nnData = qNn->get<dai::NNData>(); // 阻塞
18
19// NN 可以从多个层输出。打印所有层名称:
20cout << nnData->getAllLayerNames();
21
22// 获取名为 "Layer1_FP16" 的层作为 FP16
23auto layer1Data = nnData->getLayerFp16("Layer1_FP16");
24
25// 您现在可以解码 NN 的输出

功能示例

参考

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: typing.SupportsInt)
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: typing.SupportsInt)
How many Neural Compute Engines should a single thread use for inference  Parameter ``numNCEPerThread``:     Number of NCE per thread
method
setNumPoolFrames(self, numFrames: typing.SupportsInt)
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

需要帮助?

请访问讨论论坛以获取技术支持或您可能有的任何其他问题。