ArcFace RKNN Conversion Failure: Output is Always Zero on RV1106

  • Hello, porting a model to RKNN is a complex process that requires a solid understanding of the model itself. We do not have the capacity or resources to reproduce your testing environment, even though you have provided detailed information.

    In our experience, there are two common reasons why the model outputs all zeros:

    The input image format is incorrect (for example, the model expects BGR but receives RGB).

    The model conversion process was not properly configured, particularly the rknn.config parameters such as optimization_level and quantized_algorithm.
  • [BUG] rknn_outputs_get returns "context config invalid" on RV1103 with librknnmrt 1.6.0 + NPU driver 0.9.2
    Board: Luckfox Pico Plus (RV1103)
    Firmware: Kernel 5.10.160 (built May 6 2025)
    NPU Driver: v0.9.2
    librknnmrt: 1.6.0 (2024-01-17)
    Python: 3.11.6
    OS: Buildroot (uClibc)

    Problem:
    I cannot retrieve NPU inference results from Python. Both rknn_inputs_set and rknn_outputs_get return -5 (RKNN_ERR_CTX_INVALID) even though rknn_init, rknn_query, and rknn_run all succeed.
    Model details:

    Input: shape [1,4] float32 (dist1, dist2, rain, flow)
    Output: shape [1,1] float32
    Target platform: rv1103
    Compiled with toolkit 2.3.2

    What works:
    rknn_init() → ret=0 ctx=4913464 ✅
    rknn_query() → ret=0 n_in=1 n_out=1 ✅
    rknn_run() → ret=0 ✅

    What fails:
    E RKNN: rknn_inputs_set, context config invalid!
    rknn_inputs_set ret=-5 ❌

    E RKNN: rknn_outputs_get, context config invalid!
    rknn_outputs_get ret=-5 ❌

    Reproduction code (Python):
    pythonimport ctypes, struct

    lib = ctypes.CDLL('/oem/usr/lib/librknnmrt.so')
    lib.rknn_init.restype = ctypes.c_int
    lib.rknn_init.argtypes = [ctypes.POINTER(ctypes.c_uint32), ctypes.c_void_p,
    ctypes.c_uint32, ctypes.c_uint32, ctypes.c_void_p]
    lib.rknn_inputs_set.restype = ctypes.c_int
    lib.rknn_inputs_set.argtypes = [ctypes.c_uint32, ctypes.c_uint32, ctypes.c_void_p]
    lib.rknn_outputs_get.restype = ctypes.c_int
    lib.rknn_outputs_get.argtypes = [ctypes.c_uint32, ctypes.c_uint32,
    ctypes.c_void_p, ctypes.c_void_p]
    lib.rknn_run.restype = ctypes.c_int
    lib.rknn_run.argtypes = [ctypes.c_uint32, ctypes.c_void_p]
    lib.rknn_query.restype = ctypes.c_int
    lib.rknn_query.argtypes = [ctypes.c_uint32, ctypes.c_int,
    ctypes.c_void_p, ctypes.c_uint32]

    with open('/opt/model/luckfox_final.rknn', 'rb') as f:
    data = f.read()
    buf = ctypes.create_string_buffer(data)
    ctx = ctypes.c_uint32(0)

    # This succeeds
    ret = lib.rknn_init(ctypes.byref(ctx), buf, len(data), 0, None)
    print(f'init: ret={ret} ctx={ctx.value}') # ret=0 ctx=4913464

    # Query also works
    io = bytearray(8)
    lib.rknn_query(ctx.value, 0, (ctypes.c_uint8*8).from_buffer(io), 8)
    print(f'n_in={struct.unpack_from("I",io,0)[0]} n_out={struct.unpack_from("I",io,4)[0]}')

    # Run works
    ret = lib.rknn_run(ctx.value, None)
    print(f'run: ret={ret}') # ret=0

    # BUT outputs_get FAILS
    out = bytearray(16)
    out[0] = 1 # want_float=1
    arr = (ctypes.c_uint8*16).from_buffer(out)
    ret = lib.rknn_outputs_get(ctx.value, 1, arr, None)
    print(f'outputs_get: ret={ret}') # ret=-5 !!!
    ```

    **Output:**
    ```
    init: ret=0 ctx=4913464
    n_in=1 n_out=1
    run: ret=0
    E RKNN: rknn_outputs_get, context config invalid!
    outputs_get: ret=-5
    ```

    ---

    **Also tried:**
    - `rknn_set_io_mem` — returns 0 (success) but output buffer always reads zero
    - `rknn_mem_sync` with all modes (1, 2, 3) — no effect
    - All input formats: FLOAT32, INT8, pass_through=0/1, NCHW/NHWC — all fail with same error
    - Toolkit 1.6.0 model, 2.3.2 model, rv1103 target, rv1106 target — all same error
    - Fresh context with NO set_io_mem — `outputs_get` still returns -5

    ---

    **System info:**
    ```
    [root@luckfox root]# uname -r
    5.10.160
    [root@luckfox root]# cat /proc/version
    Linux version 5.10.160 (hxj@luckfox-System-Product-Name)
    (arm-rockchip830-linux-uclibcgnueabihf-gcc 8.3.0)
    #2 Tue May 6 20:18:43 CST 2025

    [root@luckfox root]# strings /oem/usr/lib/librknnmrt.so | grep version
    librknnmrt version: 1.6.0 (2de554906@2024-01-17T14:53:41)

    [root@luckfox root]# cat /proc/modules | grep npu
    rknpu 27019 0 - Live 0xaf935000

    [root@luckfox root]# dmesg | grep RKNPU
    RKNPU ff660000.npu: RKNPU: rknpu iommu device-tree entry not found!, using non-iommu mode
    RKNPU ff660000.npu: RKNPU: Initialized RKNPU driver: v0.9.2 for 20230825

    Question:

    Is there a newer librknnmrt.so or rknpu.ko available for Luckfox Pico Plus that fixes this?
    Is there a prebuilt rknpu.ko for kernel 5.10.160 with a newer driver version?
    Is rknn_server available for RV1103 that can bypass this issue?

    Thank you.
  • We did not participate in the development and maintenance of the entire rknn-toolkit. This library has always been a closed-source project and we are not aware of the details. If you encounter any bugs, please report them at https://github.com/airockchip/rknn-toolkit2.
    Also, at https://github.com/airockchip/rknn-toolkit2, the latest rknn_server and librknnmrt are provided.