From 0f07c2bdc85a1f809e79a9762bde37acf717e7a3 Mon Sep 17 00:00:00 2001 From: MarcA711 <40744649+MarcA711@users.noreply.github.com> Date: Sat, 23 Mar 2024 19:44:10 +0000 Subject: [PATCH] configure number of cores rather than a core mask for better user experience --- docs/docs/configuration/object_detectors.md | 14 +++++--------- frigate/detectors/plugins/rknn.py | 4 ++-- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/docs/docs/configuration/object_detectors.md b/docs/docs/configuration/object_detectors.md index cf33123f0..d0ece3ac2 100644 --- a/docs/docs/configuration/object_detectors.md +++ b/docs/docs/configuration/object_detectors.md @@ -406,8 +406,11 @@ This `config.yml` shows all relevant options to configure the detector and expla detectors: # required rknn: # required type: rknn # required - # core mask for npu - core_mask: 0b111 + # number of NPU cores used for detection + # 0 means automatic selection, 1 is one core etc + # only relevant for SoCs with multicore NPU like rk3588/s + # increase to 3 on rk3588 SoC for best performance + num_cores: 0 model: # required # name of yolov8 model or path to your own .rknn model file @@ -429,13 +432,6 @@ model: # required input_tensor: nhwc ``` -Explanation for rknn specific options: - -- **core mask** controls which cores of your NPU should be used. This option applies only to SoCs with a multicore NPU (at the time of writing this in only the RK3588/S). The easiest way is to pass the value as a binary number. To do so, use the prefix `0b` and write a `0` to disable a core and a `1` to enable a core, whereas the last digit corresponds to core0, the second last to core1, etc. You also have to use the cores in ascending order (so you can't use core0 and core2; but you can use core0 and core1). Enabling more cores can reduce the inference speed, especially when using bigger models (see section below). Examples: - - `core_mask: 0b000` or just `core_mask: 0` let the NPU decide which cores should be used. - - `core_mask: 0b001` use only core0. - - `core_mask: 0b111` use core0, core1 and core2. Fastest and default value. - - `core_mask: 0b110` use core1 and core2. **This does not** work, since core0 is disabled. ### Choosing a model diff --git a/frigate/detectors/plugins/rknn.py b/frigate/detectors/plugins/rknn.py index 6b67c2018..3d5db3526 100644 --- a/frigate/detectors/plugins/rknn.py +++ b/frigate/detectors/plugins/rknn.py @@ -18,7 +18,7 @@ supported_socs = ["rk3562", "rk3566", "rk3568", "rk3588"] class RknnDetectorConfig(BaseDetectorConfig): type: Literal[DETECTOR_KEY] - core_mask: int = Field(default=7, ge=0, le=7, title="Core mask for NPU.") + num_cores: int = Field(default=0, ge=0, le=3, title="Number of NPU cores.") class Rknn(DetectionApi): @@ -29,7 +29,7 @@ class Rknn(DetectionApi): self.width = config.model.width soc = self.get_soc() - core_mask = config.core_mask + core_mask = 2**config.num_cores - 1 model_properties = self.get_model_properties( config.model.path or "default-yolov8n", soc