DepthAI v2 has been superseded by DepthAI v3. You are viewing legacy documentation.

本页目录

  • CPU usage
  • RAM 使用
  • 降低 RAM 消耗

管道调试

您可以通过更改调试级别来启用日志记录。默认设置为 warning,但可以设置更详细的级别以帮助调试问题。以下级别可供使用:
调试级别信息
critical仅当发生严重错误,导致程序停止或崩溃时。
error错误不会停止程序,但无法完成操作。示例:当 ImageManip 裁剪 ROI 超出范围时,会打印错误,裁剪将不会进行。当 NeuralNetwork 接收到的帧形状(宽度/高度/通道)与 .blob 不匹配时。
warn在用户操作可以改善或修复特定行为的情况下打印警告。示例:当 API 更改时,旧 API 样式将被弃用,并向用户显示警告。
info将打印有关 CPU/RAM 消耗、温度、CMX 切片和 SHAVE 核心分配的信息。
debug特别在启动和停止管道时有用。Debug 将打印:设备初始化信息,例如管道 JSON、固件/引导加载程序/OpenVINO 版本。设备/XLink 如何关闭/释放。
traceTrace 将在从设备接收到消息时打印出该消息。
调试可以通过代码(通过 API)或通过环境变量启用。

使用API进行调试

Python
1with dai.Device() as device: # 初始化设备
2    # 设置调试级别
3    device.setLogLevel(dai.LogLevel.DEBUG)
4    device.setLogOutputLevel(dai.LogLevel.DEBUG)
其中 setLogLevel 设置详细级别,用于过滤从设备发送到主机的消息,而 setLogOutputLevel 设置详细级别,用于过滤在主机(标准输出)上打印的消息。这种差异使我们能够内部捕获日志消息而不打印到标准输出,并将其用于例如在其他地方显示或分析。

使用环境变量 DEPTHAI_LEVEL 进行调试

使用环境变量(而非直接在代码中配置)设置调试级别,可以提供额外的详细信息。这包括 CMXSHAVE 使用情况等指标,以及管道中每个节点处理单个帧所花费的时间。以下是 RGB预览INFO 模式下的日志消息示例:
Command Line
1[184430102189660F00] [2.1] [0.675] [system] [info] DepthCamera allocated resources: shaves: [0-12] no cmx slices.
2[184430102189660F00] [2.1] [0.675] [system] [info] SIPP (Signal Image Processing Pipeline) internal buffer size '18432'B, DMA buffer size: '16384'B
3[184430102189660F00] [2.1] [0.711] [system] [info] ImageManip internal buffer size '285440'B, shave buffer size '34816'B
4[184430102189660F00] [2.1] [0.711] [system] [info] ColorCamera allocated resources: no shaves; cmx slices: [13-15]
5ImageManip allocated resources: shaves: [15-15] no cmx slices.
以下是 深度预览TRACE 模式下的日志消息示例:
Command Line
1[19443010513F4D1300] [0.1.2] [2.014] [MonoCamera(0)] [trace] Mono ISP took '0.866377' ms.
2[19443010513F4D1300] [0.1.2] [2.016] [MonoCamera(1)] [trace] Mono ISP took '1.272838' ms.
3[19443010513F4D1300] [0.1.2] [2.019] [StereoDepth(2)] [trace] Stereo rectification took '2.661958' ms.
4[19443010513F4D1300] [0.1.2] [2.027] [StereoDepth(2)] [trace] Stereo took '7.144515' ms.
5[19443010513F4D1300] [0.1.2] [2.028] [StereoDepth(2)] [trace] 'Median' pipeline took '0.772257' ms.
6[19443010513F4D1300] [0.1.2] [2.028] [StereoDepth(2)] [trace] Stereo post processing (total) took '0.810216' ms.
7[2024-05-16 14:27:51.294] [depthai] [trace] Received message from device (disparity) - parsing time: 11µs, data size: 256000

Linux/MacOS

Command Line
1DEPTHAI_LEVEL=debug python3 script.py

Windows PowerShell

Command Line
1$env:DEPTHAI_LEVEL='debug'
2python3 script.py
3
4# 之后关闭调试
5Remove-Item Env:DEPTHAI_LEVEL

Windows CMD

Command Line
1set DEPTHAI_LEVEL=debug
2python3 script.py
3
4# 之后关闭调试
5set DEPTHAI_LEVEL=

CPU usage

When setting the Debug Level to debug (or lower), depthai will also print our CPU usage for LeonOS and LeonRT. CPU usage at 100% (or close to it) can cause many undesirable effects, such as higher frame latency, lower FPS, and in some cases even firmware crash.Compared to OAK USB cameras, OAK PoE cameras will have increased CPU consumption, as the networking stack is running on the LeonOS core. The easiest way to reduce CPU consumtpion is to reduce the pipeline complexity, or to reduce FPS of the cameras, as they are the main consumers of CPU (running 3A algorithms).Not having 100% CPU usage also drastically decreased frame latency, in the example for the script below it went from ~710 ms to ~110ms:

RAM 使用

所有基于 RVC2 的 OAK 设备均配备 512 MiB(4 Gbit)板载 RAM,用于固件(约 15MB)、资产(几 KB 到 100MB,例如 NN 模型)以及其他资源(例如存储消息的消息池)。如果启用 info(请参阅 管道调试 部分),您将看到 RAM 的使用情况:
Command Line
1[info] Memory Usage - DDR: 41.23 / 358.82 MiB, CMX: 2.17 / 2.50 MiB,
2LeonOS Heap: 20.70 / 78.63 MiB, LeonRT Heap: 3.51 / 23.84 MiB
如您所见,RAM 被分配给两个 LEON(CPU)核心、CMX(用于图像处理)以及 DDR(其他所有内容)。如果 DDR 使用量接近最大值(在此示例中为 358 MiB),您可能会遇到类似以下的错误:
Command Line
1[error] Neural network executor '0' out of '2' error: OUT_OF_MEMORY
这意味着您需要降低 RAM 消耗,接下来我们将介绍几种实现方法。

降低 RAM 消耗

  • 池大小 - 某些节点(包括 ColorCamera PointCloud ImageManip EdgeDetector MonoCamera StereoDepth VideoEncoder Warp)具有可配置的池大小(池文档请见此处)。 这意味着用户可以配置池中存储的消息数量(RAM)。如果您遇到 RAM 使用限制,最简单的降低方法就是减小池大小。配置池大小的 API 是 node.setNumFramesPool(num_frames_pool)。对于 ColorCamera,用户需要指定 5 个池大小 colorCam.setNumFramesPool(raw, isp, preview, video, still)。请注意,将池大小减小到 2 以下会导致管道问题
  • 大帧 如果在 RGB 视频 示例中将分辨率从 1080P 改为 4K,DDR 使用量将从 41 MiB 增加到 161 MiB。这是因为与 1080P 帧相比,4K 需要使用 4 倍的 RAM。降低 RAM 消耗的一个简单方法是使用较低的分辨率/较小的帧。
  • VideoEncoder VideoEncoder 节点可能会消耗大量 RAM,尤其是在高分辨率下。例如,RGB 编码 示例消耗 259 MiB。如果将分辨率从 4K 改为 1080P,DDR 消耗将降至仅 65 MiB。
  • ImageManip 每个 ImageManip 节点都有自己的(输出)池(默认 4 帧),因此如果有多个 ImageManip 处理高分辨率帧,将消耗大量 DDR RAM。默认情况下,每个池“槽位”会消耗 1 MiB,即使只是一个 300x300 的 RGB 帧(270kB)。因此,指定输出帧大小也可以降低 RAM,例如,对于 300x300 RGB 帧,您可以设置 manip.setMaxOutputFrameSize(270000)
  • XLinkInImageManip 类似,每个 XLinkIn 节点也有自己的消息池。默认情况下,每个 XLinkIn 会消耗 40 MiB,因为每个池“槽位”保留了 5 MiB,并且池中有 8 个“槽位”。如果您从主机向设备发送 300x300 RGB 帧,您可以设置 xin.setMaxDataSize(270000),并限制每个池的消息数量 xin.setNumFrames(4)。这会将 DDR RAM 消耗从 40 MiB 降至约 1 MiB。
如果您只是从主机发送控制/配置信息,可以设置 xin.setMaxDataSize(1),因为 CameraControl ImageManipConfig 只包含元数据(不包含任何数据,例如 NNData / ImgFrame/ Buffer)。