Apache License 2.0

技术解读

以下内容由 GitRead 中文社区 编辑团队基于项目 README 与官方资料整理, 结合中文开发者的常见使用场景补充技术选型建议。具体以项目官方文档为准。

技术深度分析:Kendryte/nncase

项目背景与痛点

Kendryte/nncase 源自于凯迪思公司为自家 AI 架构所设计的一款深度学习编译栈。它本质上是为了解决微架构环境下深度学习模型部署的性能和效率问题。在边缘计算设备上运行深度学习模型通常面临计算资源有限与能效比低下的瓶颈。通过有针对性地编译器优化,nncase 帮助开发者更轻松地实现轻量级 AI 应用部署,适用于各类嵌入式系统。这意味着更好的能效比,同时降低了开发与部署的成本。

核心技术揭秘

nncase 的核心在于其编译优化技术栈的设计与实现。编译器的核心任务是将高级语言转化为机器语言,而在 nncase 中更是引入了一系列的中间表示与优化步骤来适配各种底层硬件特性。为了在低功耗硬件上高效运行,nncase 使用了许多精巧的设计。

graph TD A[模型定义] --> B("ONNX 优化") B --> C("代码生成与优化") C --> D("Kendryte 特定优化") D --> E[二进制输出] B -->|"Fusion & Quantization"| F{"模型优化决策"} F -->|"量化参数"| C

在上述流程中,模型从高级表示(如 ONNX)转换为优化更接近目标硬件的形式。重要的是它会执行量化及融合操作,通过减少计算精度来节省算力开销,同时保证模型性能不大幅降损。后面进行代码生成,进一步结合硬件特性如指令集架构特性优化指令序列以最佳利用计算资源。最终生成适合在 Kendryte 硬件上高质量运行的二进制文件。

功能亮点与差异

nncase 的独特之处在于对 Kendryte AI 芯片的深度优化,这归功于其特定的中间表示层与编译优化设计。这一工具包关注的是 AI 模型的能效比和可执行性,而不少竞品可能只偏重模型缩减。nncase 的优势在于代码生成与优化阶段,它能够针对特定的 AI 硬件架构产出高性能的执行代码,减少资源消耗,提升模型执行效率。

应用场景与落地建议

在生产环境中使用 nncase,开发者应该重点留意模型的大小与量化效果的平衡,因为这两者直接影响性能与准确性。选择合适的模型和优化策略对于成功部署至关重要。同时,在进行复杂模型的整理优化时,应充分考虑目标硬件的计算能力,确保模型不会超出硬件的性能边界。

这一编译栈非常适合需要在嵌入式设备、企业级或物联网等低能量消耗场景下运行深度学习任务的项目。综上所述,对于希望在嵌入式平台优化应用的人来说,nncase 至关重要,提供了执行深度学习任务的强大工具。

综合评价

Kendryte/nncase 有效解决了微架构下深度学习应用的性能优化问题。它凭借巧妙的编译优化技术,提升了其在嵌入式 AI 应用中的表现。然而,开发者在使用时需要了解其特定优化所影响的范围,尤其是硬件适配部分。总的来说,nncase 是一款强大的工具,适用于对低功耗高效率有严格要求的健康、安全监控、智能摄像头等智能物联网场景,可以大大提高计算效率和降低硬件需求。

关于

GitHub 原始描述(英文)

Open deep learning compiler stack for Kendryte AI accelerators ✨

描述取自 GitHub 官方 API,保持仓库作者书写的原文。

简要分析

热度分
1342
价值分
604
活跃状态
活跃

语言占比

C
C#
C++
CMake
HLSL
HTML
Jinja
Python
Shell

Release

README

nncase

GitHub repository Gitee repository GitHub release

切换中文

nncase is a neural network compiler for AI accelerators.

Telegram: nncase community Technical Discussion QQ Group: 790699378 . Answer: 人工智能


K230

Install

  • Linux:

    pip install nncase nncase-kpu
    
  • Windows:

    1. pip install nncase
    2. Download `nncase_kpu-2.x.x-py2.py3-none-win_amd64.whl` in below link.
    3. pip install nncase_kpu-2.x.x-py2.py3-none-win_amd64.whl
    

All version of nncase and nncase-kpu in Release.

Supported operators

benchmark test

kind model shape quant_type(If/W) nncase_fps tflite_onnx_result accuracy info
Image Classification mobilenetv2 [1,224,224,3] u8/u8 600.24 top-1 = 71.3%
top-5 = 90.1%
top-1 = 71.1%
top-5 = 90.0%
dataset(ImageNet 2012, 50000 images)
tflite
resnet50V2 [1,3,224,224] u8/u8 86.17 top-1 = 75.44%
top-5 = 92.56%
top-1 = 75.11%
top-5 = 92.36%
dataset(ImageNet 2012, 50000 images)
onnx
yolov8s_cls [1,3,224,224] u8/u8 130.497 top-1 = 72.2%
top-5 = 90.9%
top-1 = 72.2%
top-5 = 90.8%
dataset(ImageNet 2012, 50000 images)
yolov8s_cls(v8.0.207)
Object Detection yolov5s_det [1,3,640,640] u8/u8 23.645 bbox
mAP50-90 = 0.374
mAP50 = 0.567
bbox
mAP50-90 = 0.369
mAP50 = 0.566
dataset(coco val2017, 5000 images)
yolov5s_det(v7.0 tag, rect=False, conf=0.001, iou=0.65)
yolov8s_det [1,3,640,640] u8/u8 9.373 bbox
mAP50-90 = 0.446
mAP50 = 0.612
mAP75 = 0.484
bbox
mAP50-90 = 0.404
mAP50 = 0.593
mAP75 = 0.45
dataset(coco val2017, 5000 images)
yolov8s_det(v8.0.207, rect = False)
Image Segmentation yolov8s_seg [1,3,640,640] u8/u8 7.845 bbox
mAP50-90 = 0.444
mAP50 = 0.606
mAP75 = 0.484
segm
mAP50-90 = 0.371
mAP50 = 0.578
mAP75 = 0.396
bbox
mAP50-90 = 0.444
mAP50 = 0.606
mAP75 = 0.484
segm
mAP50-90 = 0.371
mAP50 = 0.579
mAP75 = 0.397
dataset(coco val2017, 5000 images)
yolov8s_seg(v8.0.207, rect = False, conf_thres = 0.0008)
Pose Estimation yolov8n_pose_320 [1,3,320,320] u8/u8 36.066 bbox
mAP50-90 = 0.6
mAP50 = 0.843
mAP75 = 0.654
keypoints
mAP50-90 = 0.358
mAP50 = 0.646
mAP75 = 0.353
bbox
mAP50-90 = 0.6
mAP50 = 0.841
mAP75 = 0.656
keypoints
mAP50-90 = 0.359
mAP50 = 0.648
mAP75 = 0.357
dataset(coco val2017, 2346 images)
yolov8n_pose(v8.0.207, rect = False)
yolov8n_pose_640 [1,3,640,640] u8/u8 10.88 bbox
mAP50-90 = 0.694
mAP50 = 0.909
mAP75 = 0.776
keypoints
mAP50-90 = 0.509
mAP50 = 0.798
mAP75 = 0.544
bbox
mAP50-90 = 0.694
mAP50 = 0.909
mAP75 = 0.777
keypoints
mAP50-90 = 0.508
mAP50 = 0.798
mAP75 = 0.54
dataset(coco val2017, 2346 images)
yolov8n_pose(v8.0.207, rect = False)
yolov8s_pose [1,3,640,640] u8/u8 5.568 bbox
mAP50-90 = 0.733
mAP50 = 0.925
mAP75 = 0.818
keypoints
mAP50-90 = 0.605
mAP50 = 0.857
mAP75 = 0.666
bbox
mAP50-90 = 0.734
mAP50 = 0.925
mAP75 = 0.819
keypoints
mAP50-90 = 0.604
mAP50 = 0.859
mAP75 = 0.669
dataset(coco val2017, 2346 images)
yolov8s_pose(v8.0.207, rect = False)

Demo

eye gaze space_resize face pose
gif gif

K210/K510

Supported operators


Features

  • Supports multiple inputs and outputs and multi-branch structure
  • Static memory allocation, no heap memory acquired
  • Operators fusion and optimizations
  • Support float and quantized uint8 inference
  • Support post quantization from float model with calibration dataset
  • Flat model with zero copy loading

Architecture

nncase arch

Build from source

It is recommended to install nncase directly through pip. At present, the source code related to k510 and K230 chips is not open source, so it is not possible to use nncase-K510 and nncase-kpu (K230) directly by compiling source code.

If there are operators in your model that nncase does not yet support, you can request them in the issue or implement them yourself and submit the PR. Later versions will be integrated, or contact us to provide a temporary version. Here are the steps to compile nncase.

git clone https://github.com/kendryte/nncase.git
cd nncase
mkdir build && cd build

# Use Ninja
cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=./install
ninja && ninja install

# Use make
cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=./install
make && make install

Resources

Canaan developer community

Canaan developer community contains all resources related to K210, K510, and K230.

  • 资料下载 --> Pre-compiled images available for the development boards corresponding to the three chips.
  • 文档 --> Documents corresponding to the three chips.
  • 模型库 --> Examples and code for industrial, security, educational and other scenarios that can be run on the K210 and K230.
  • 模型训练 --> The model training platform for K210 and K230 supports the training of various scenarios.

Bilibili


评论

暂无评论