Skip to main content

RetinaFace

Environment Setup

info

Follow RKNN Installation to set up the environment.

Follow RKNN Model Zoo to download the example files.

Model Download

Download the ONNX model file.

X64 Linux PC
cd rknn_model_zoo/examples/RetinaFace/model/
bash download_model.sh

Model Conversion

Select the target platform.

X64 Linux PC
export TARGET_PLATFORM=rk3588

Convert the ONNX model to an RKNN model.

X64 Linux PC
cd ../python/
python convert.py ../model/RetinaFace_mobile320.onnx ${TARGET_PLATFORM}

C API

Build the Example

Go to the rknn_model_zoo directory and run build-linux.sh to build.

X64 Linux PC
cd ../../..
bash build-linux.sh -t ${TARGET_PLATFORM} -a aarch64 -d RetinaFace

Sync Files to the Device

Copy the built demo directory under the install folder to the device.

X64 Linux PC
cd install/${TARGET_PLATFORM}_linux_aarch64/
scp -r rknn_RetinaFace_demo/ user@your_device_ip:target_directory

Run the Example

Export the runtime libraries to the environment variable.

Device
cd rknn_RetinaFace_demo/
export LD_LIBRARY_PATH=./lib

Run the example.

Device
./rknn_retinaface_demo ./model/RetinaFace.rknn ./model/test.jpg
$ ./rknn_retinaface_demo ./model/RetinaFace.rknn ./model/test.jpg
model input num: 1, output num: 3
input tensors:
index=0, name=input0, n_dims=4, dims=[1, 320, 320, 3], n_elems=307200, size=307200, fmt=NHWC, type=INT8, qnt_type=AFFINE, zp=-14, scale=1.074510
output tensors:
index=0, name=output0, n_dims=3, dims=[1, 4200, 4, 0], n_elems=16800, size=16800, fmt=UNDEFINED, type=INT8, qnt_type=AFFINE, zp=0, scale=0.044699
index=1, name=572, n_dims=3, dims=[1, 4200, 2, 0], n_elems=8400, size=16800, fmt=UNDEFINED, type=FP16, qnt_type=AFFINE, zp=0, scale=1.000000
index=2, name=571, n_dims=3, dims=[1, 4200, 10, 0], n_elems=42000, size=42000, fmt=UNDEFINED, type=INT8, qnt_type=AFFINE, zp=-22, scale=0.086195
model is NHWC input fmt
model input height=320, width=320, channel=3
origin size=640x427 crop size=640x416
input image: 640 x 427, subsampling: 4:2:0, colorspace: YCbCr, orientation: 1
scale=0.500000 dst_box=(0 54 319 265) allow_slight_change=1 _left_offset=0 _top_offset=54 padding_w=0 padding_h=108
rga_api version 1.10.1_[0]
fill dst image (x y w h)=(0 0 320 320) with color=0x72727272
RgaCollorFill(1819) RGA_COLORFILL fail: Invalid argument
RgaCollorFill(1820) RGA_COLORFILL fail: Invalid argument
161 im2d_rga_impl rga_task_submit(2171): Failed to call RockChipRga interface, please use 'dmesg' command to view driver error log.
161 im2d_rga_impl rga_dump_channel_info(1500): src_channel:
rect[x,y,w,h] = [0, 0, 0, 0]
image[w,h,ws,hs,f] = [0, 0, 0, 0, rgba8888]
buffer[handle,fd,va,pa] = [0, 0, 0, 0]
color_space = 0x0, global_alpha = 0x0, rd_mode = 0x0

161 im2d_rga_impl rga_dump_channel_info(1500): dst_channel:
rect[x,y,w,h] = [0, 0, 320, 320]
image[w,h,ws,hs,f] = [320, 320, 320, 320, rgb888]
buffer[handle,fd,va,pa] = [2, 0, 0, 0]
color_space = 0x0, global_alpha = 0xff, rd_mode = 0x1

161 im2d_rga_impl rga_dump_opt(1550): opt version[0x0]:

161 im2d_rga_impl rga_dump_opt(1551): set_core[0x0], priority[0]

161 im2d_rga_impl rga_dump_opt(1554): color[0x72727272]
161 im2d_rga_impl rga_dump_opt(1563):

161 im2d_rga_impl rga_task_submit(2180): acquir_fence[-1], release_fence_ptr[0x0], usage[0x280000]

rknn_run
face @(302 72 476 296) score=0.999023
write_image path: result.jpg width=640 height=427 channel=3 data=0x6dfc610

Result Preview

Python API

Activate the virtual environment

Device
conda activate rknn

Run the Example

Copy the related files to the device and run the following commands.

Device
python RetinaFace.py --model_path ../model/RetinaFace.rknn --target ${TARGET_PLATFORM}
$ python RetinaFace.py --model_path ../model/RetinaFace.rknn --target rk3588
/home/radxa/miniforge3/envs/rknn/lib/python3.12/site-packages/rknn/api/rknn.py:51: UserWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html. The pkg_resources package is slated for removal as early as 2025-11-30. Refrain from using this package or pin to Setuptools<81.
self.rknn_base = RKNNBase(cur_path, verbose)
I rknn-toolkit2 version: 2.3.2
done
--> Init runtime environment
I target set by user is: rk3588
done
--> Running model
W inference: The 'data_format' is not set, and its default value is 'nhwc'!
image_size: (320, 320) num_priors= 4200
face @ (302 74 478 300) 0.999023
save image in ./result.jpg

Result Preview

    You need to be logged into GitHub to post a comment. If you are already logged in, please ignore this message.

    Radxa-docs © 2026 by Radxa Computer (Shenzhen) Co.,Ltd. is licensed under CC BY 4.0