Skip to main content

Meta RKNN Toolkit

Project description

metarknn

metarknn部署通用框架

1、安装最新版 meta-cv

pip install meta-cv

2、安装最新版 meta-rknn

pip install meta-rknn

3、目标检测示例(参考detection_demo.py代码)

import platform, cv2
import metarknn as mr

Detection = mr.DetectionRKNN

y = Detection(model_path='models/yolov8m.rknn',
              input_width=640,
              input_height=480,
              confidence_thresh=0.5,
              nms_thresh=0.3,
              class_names=classnames,
              device_id=0)

# 如需本地运行,需调用下面一句进行模型转换并加载,板端无需运行
if platform.machine() == 'x86_64':
    y.convert_and_load(quantize=False,  # 是否int8量化
                       dataset='dataset.txt',  # 量化使用图片路径文件
                       is_hybrid=True)  # 是否进行混合量化

img = cv2.imread('models/bus.jpg')
_dets, _scores, _labels = y.predict(cv2.cvtColor(img, cv2.COLOR_BGR2RGB), use_preprocess=True)

# 显示
y.show(img, _dets, _scores, _labels)
cv2.imwrite("models/bus.png", img)

4、实例分割示例(参考segment_demo.py代码)

import platform, cv2
import metarknn as mr

Segment = mr.SegmentRKNN

y = Segment(model_path='models/yolov8m-seg.rknn',
            input_width=640,
            input_height=480,
            confidence_thresh=0.5,
            nms_thresh=0.3,
            class_names=classnames,
            device_id=0)

# 如需本地运行,需调用下面一句进行模型转换并加载,板端无需运行
if platform.machine() == 'x86_64':
    y.convert_and_load(quantize=False,  # 是否int8量化
                       dataset='dataset.txt',  # 量化使用图片路径文件
                       is_hybrid=True)  # 是否进行混合量化

img = cv2.imread('models/bus.jpg')
_dets, _scores, _labels = y.predict(cv2.cvtColor(img, cv2.COLOR_BGR2RGB), use_preprocess=True)

# 显示
y.show(img, _dets, _scores, _labels)
cv2.imwrite("models/bus.png", img)

5、模型转换与量化(本地运行)

import metarknn as mr
from mr.quantization import Quantization

q = Quantization(model_path,    # onnx模型路径
                 dataset,   # dataset文件路径
                 output_names=["output0", "output1"])   # 定义模型输出层
if is_hybrid:   # 是否混合量化
    self.model = q.hybrid_convert()
else:   # 非混合量化(是否int8量化)
    self.model = q.convert(quantize)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

meta-rknn-0.1.0.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

meta_rknn-0.1.0-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

Details for the file meta-rknn-0.1.0.tar.gz.

File metadata

  • Download URL: meta-rknn-0.1.0.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.9.6 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/1.0.0 urllib3/1.26.15 tqdm/4.64.0 importlib-metadata/4.2.0 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.6.13

File hashes

Hashes for meta-rknn-0.1.0.tar.gz
Algorithm Hash digest
SHA256 26a26e86a89de83e6039649d11d42dff3eb174c6e154e1ef257d2edf71c44159
MD5 3532a8630651d64cdaff7caa98123442
BLAKE2b-256 eb729e8105f3110be551145d9808c51a81d91160c3168610029d408be63ecb1b

See more details on using hashes here.

File details

Details for the file meta_rknn-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: meta_rknn-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.9.6 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/1.0.0 urllib3/1.26.15 tqdm/4.64.0 importlib-metadata/4.2.0 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.6.13

File hashes

Hashes for meta_rknn-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ae17dbedbc6153301425e774783bcf4bc297774c61c0709e768a965f319a1bfc
MD5 8a65c3e6e021651c52e1a6799ba3eb72
BLAKE2b-256 3c5caf4565c950c342289a08180ba4ea55acfddac011776950d9d7d73c609bed

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page