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、图像分类示例(参考classification_demo.py代码)

import cv2, platform
import metarknn as m

Classification = m.Classification

y = Classification(model_path='models/mixnet_xl_bs24_2.rknn',
                   input_width=224,
                   input_height=224,
                   use_preprocess=True,
                   class_names=classnames,
                   device_id=0)

batch_size = 24
img = cv2.imread('models/bottle.jpg')
img_list = [img[:, :, ::-1]] * batch_size if batch_size > 1 else img[:, :, ::-1]
_dets, _scores, _labels = y.predict(img_list)

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

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

import cv2, platform
import metarknn as m

Detection = m.Detection

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

batch_size = 1
img = cv2.imread('models/bus.jpg')
img_list = [img[:, :, ::-1]] * batch_size if batch_size > 1 else img[:, :, ::-1]
_dets, _scores, _labels = y.predict(img_list)

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

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

import platform, cv2
import metarknn as m

Segment = m.Segment

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

batch_size = 1
img = cv2.imread('models/bus.jpg')
img_list = [img[:, :, ::-1]] * batch_size if batch_size > 1 else img[:, :, ::-1]
_dets, _scores, _labels = y.predict(img_list)

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

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

import metarknn as m

Quantization = m.Quantization

q = Quantization(model_path,    # onnx模型路径
                 dataset,   # dataset文件路径
                 mean=[[0, 0, 0]],
                 std=[[255, 255, 255]],
                 batch_size=1)   # 定义模型输出层

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.1.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

meta_rknn-0.1.1-py3-none-any.whl (11.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: meta-rknn-0.1.1.tar.gz
  • Upload date:
  • Size: 4.8 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.1.tar.gz
Algorithm Hash digest
SHA256 3ce6bd5206faa83671e62eeb7301d3edaee7fbf3aee6e348a5ad9e0ed8ab2817
MD5 ab60fd9838b8fdee9b30e3aefe3269f2
BLAKE2b-256 7d2e9e61ff11e2d0947a70530fbd2f68c1c22b71d70afce7441530948c24aa12

See more details on using hashes here.

File details

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

File metadata

  • Download URL: meta_rknn-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 11.1 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2c42582cb3887e458975b60ada8bebcd12274ce344ce192b83498b5457ecc26b
MD5 fb525bd8f20bfc54c157f138d9f47855
BLAKE2b-256 268cd3fe6f48f51db8814e3854235db78709a52fbfee0c188c297e2508491c22

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