Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How use " Ultra-Light-Fast-Generic-Face-Detector-1M" on RKNN? #267

Open
VistanaGit opened this issue Oct 25, 2021 · 1 comment
Open

How use " Ultra-Light-Fast-Generic-Face-Detector-1M" on RKNN? #267

VistanaGit opened this issue Oct 25, 2021 · 1 comment

Comments

@VistanaGit
Copy link

I need to use Ultra-lightweight face detection model for a face recognition project on a dev board. For this application, it requires to convert the model to rknn model and run the converted model on rknn. If there is any solution , could you please help me to use Ultra-lightweight face detection mode on RKNN?, Thanks

@KorolLich
Copy link

KorolLich commented Nov 18, 2024

@VistanaGit Hi! You can try something like this:

import numpy as np
from rknn.api import RKNN

MODEL_PATH = "models/onnx/version-RFB-320_new.onnx"
MODEL_NAME = MODEL_PATH.split("/")[-1]

# Initialize RKNN object
rknn: RKNN = RKNN(verbose=False)

if rknn.config(target_platform='rk3588'): #dynamic_input=DYNAMIC_INPUT
    print("RKNN config failed")
    exit(1)

# Load ONNX model
# input_size_list = [[1, 3, 240, 320]]
ret = rknn.load_onnx(model=MODEL_PATH) #, inputs=['modelInput'], input_size_list=input_size_list

# Check for successful model loading
if ret != 0:
    print("Loading ONNX model failed")
    exit(1)

ret = rknn.build(do_quantization=False, dataset="./dataset.txt")

if ret != 0:
    print("Building RKNN model failed")
    exit(1)

if rknn.init_runtime():
    print("RKNN initialization failed")
    exit(1)

rknn_model_path = MODEL_PATH.replace(".onnx", ".rknn")

ret = rknn.export_rknn(rknn_model_path)
if ret != 0:
    print("Export failed")
    rknn.release()
    exit(ret)

input_data = np.random.rand(1, 240, 320, 3).astype(np.float32)
outputs = rknn.inference(inputs=[input_data])
rknn.release()

It is working for me with rknn-toolkit2==2.2.0. Make sure that you have the same versions for rknn-toolkit2, rknn-toolkit-lite and RKNPU driver on your board

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants