blakeblackshear/frigate · critical · RuntimeError

Failed to initialize RKNN runtime

Error message

Failed to initialize RKNN runtime

What it means

The RKNN runtime failed to initialize after the .rknn model file was successfully loaded. RKNNRuntimeLite.init_runtime returned a non-zero status, which usually means the NPU device is unavailable, the core_mask is invalid for the SoC, or the RKNN runtime version does not match the model/toolkit version. This is raised as RuntimeError from _load_model during detector __init__.

Source

Thrown at frigate/detectors/detection_runners.py:485

        self.model_type = model_type
        self.core_mask = core_mask
        self.rknn = None
        self._load_model()

    def _load_model(self):
        """Load the RKNN model."""
        try:
            from rknnlite.api import RKNNLite

            self.rknn = RKNNLite(verbose=False)

            if self.rknn.load_rknn(self.model_path) != 0:
                logger.error(f"Failed to load RKNN model: {self.model_path}")
                raise RuntimeError("Failed to load RKNN model")

            if self.rknn.init_runtime(core_mask=self.core_mask) != 0:
                logger.error("Failed to initialize RKNN runtime")
                raise RuntimeError("Failed to initialize RKNN runtime")

            logger.info(f"Successfully loaded RKNN model: {self.model_path}")

        except ImportError:
            logger.error("RKNN Lite not available")
            raise ImportError("RKNN Lite not available") from None
        except Exception as e:
            logger.error(f"Error loading RKNN model: {e}")
            raise

    def get_input_names(self) -> list[str]:
        """Get input names for the model."""
        # For detection models, we typically use "input" as the default input name
        # For CLIP models, we need to determine the model type from the path
        model_name = os.path.basename(self.model_path).lower()

        if "vision" in model_name:
            return ["pixel_values"]

View on GitHub (pinned to ca18b8dc13)

Solutions

  1. Verify the NPU is visible in the container (ls /dev/dri, dmesg | grep rknpu) and run Frigate with the device mapped and privileged mode enabled
  2. Ensure the rknn-toolkit-lite2 and librknnrt.so runtime versions match the rknn-toolkit2 version used to convert the model (re-export or upgrade the runtime)
  3. Set a core_mask valid for your SoC (single core masks like NPU_CORE_0 on RK356x; multi-core masks only on RK3588)
  4. Re-convert the model with a matching toolkit version and confirm it initializes with the rknn_toolkit_lite2 python API directly on the device

Example fix

# before
core_mask: 3  # NPU_CORE_0_1, invalid on RK356x
# after
core_mask: 0  # NPU_CORE_AUTO / single core for RK356x
Defensive patterns

Strategy: validation

Validate before calling

import subprocess

def npu_available() -> bool:
    try:
        return subprocess.run(['cat','/sys/kernel/debug/rknpu/version'],capture_output=True).returncode == 0 or bool(__import__('glob').glob('/dev/dri/*'))
    except Exception:
        return False

Try / catch

try:
    detector = LocalDetector(detector_config)
except RuntimeError as e:
    if 'initialize RKNN runtime' in str(e):
        logger.error('RKNN NPU unavailable, check device mapping/core_mask/runtime version')
    raise

Prevention

When it happens

Trigger: Calling the RKNN detection runner's __init__ (which calls _load_model) where rknn.load_rknn succeeds but rknn.init_runtime(core_mask=self.core_mask) != 0. Happens on non-Rockchip hosts, wrong core_mask for the SoC (e.g. dual-core mask on single-core NPU), missing /dev/dri or NPU kernel driver, or rknn-toolkit-lite2 version mismatch with the model.

Common situations: Running the Frigate container without privileged mode / mapped NPU device on RK3588; using a model compiled with a newer rknn-toolkit2 than the installed rknn-toolkit-lite2; specifying core_mask=NPU_CORE_0_1 on an RK356x which has one NPU core; host librknnrt.so version mismatch.

Related errors


AI-assisted analysis of blakeblackshear/frigate@ca18b8dc13 (2026-08-27). Data as JSON: /api/errors/9c5a15fc838ebe8e. Report an issue: GitHub.