Tencent/ncnn
GitHub: Tencent/ncnn
腾讯开源的高性能神经网络前向推理框架,专为移动端和边缘设备极致优化,让深度学习模型在手机上高效离线运行。
Stars: 23034 | Forks: 4418

# ncnn
[](LICENSE.txt)
[](https://github.com/Tencent/ncnn/releases)
[](https://codecov.io/gh/Tencent/ncnn)
ncnn 是一个为手机端极致优化的高性能神经网络前向计算框架。
ncnn 从设计之初深刻考虑手机端的部署和使用。
无第三方依赖,跨平台,手机端 cpu 的速度快于目前所有已知的开源框架。
基于 ncnn,开发者能够将深度学习算法轻松移植到手机端高效执行,
开发出人工智能 APP,将 AI 带到你的指尖。
ncnn 目前已在腾讯多款应用中使用,如:QQ,Qzone,微信,天天 P 图等。
ncnn 是一个为手机端极致优化的高性能神经网络前向计算框架。
ncnn 从设计之初深刻考虑手机端的部署和使用。
无第三方依赖,跨平台,手机端 cpu 的速度快于目前所有已知的开源框架。
基于 ncnn,开发者能够将深度学习算法轻松移植到手机端高效执行,
开发出人工智能 APP,将 AI 带到你的指尖。
ncnn 目前已在腾讯多款应用中使用,如:QQ,Qzone,微信,天天 P 图等。
## 下载与构建状态
https://github.com/Tencent/ncnn/releases/latest
## 支持大部分常用的 CNN 网络
## 支持大部分常用的 CNN 网络
- 经典 CNN:
[VGG](https://github.com/BVLC/caffe/wiki/Model-Zoo#models-used-by-the-vgg-team-in-ilsvrc-2014)
[AlexNet](https://github.com/BVLC/caffe/tree/9b891540183ddc834a02b2bd81b31afae71b2153/models/bvlc_alexnet)
[GoogleNet](https://github.com/BVLC/caffe/tree/9b891540183ddc834a02b2bd81b31afae71b2153/models/bvlc_googlenet)
Inception
...
- 实用 CNN:
[ResNet](https://github.com/tornadomeet/ResNet)
[DenseNet](https://github.com/liuzhuang13/DenseNet)
[SENet](https://github.com/hujie-frank/SENet)
[FPN](https://github.com/unsky/FPN)
...
- 轻量级 CNN:
[SqueezeNet](https://github.com/forresti/SqueezeNet)
[MobileNetV1](https://github.com/tensorflow/models/blob/master/research/slim/nets/mobilenet_v1.md)
[MobileNetV2/V3](https://github.com/tensorflow/models/blob/master/research/slim/nets/mobilenet/README.md)
[ShuffleNetV1](https://github.com/farmingyard/ShuffleNet)
[ShuffleNetV2](https://github.com/opconty/keras-shufflenetV2)
[MNasNet](https://github.com/tensorflow/models/tree/master/research/slim/nets/nasnet)
...
- 人脸检测:
[MTCNN](https://github.com/ipazc/mtcnn)
[RetinaFace](https://github.com/biubug6/Pytorch_Retinaface)
[scrfd](https://github.com/nihui/ncnn-android-scrfd)
...
- 检测:
[VGG-SSD](https://github.com/lzx1413/CAFFE_SSD)
[MobileNet-SSD](https://github.com/chuanqi305/MobileNet-SSD)
[SqueezeNet-SSD](https://github.com/chuanqi305/SqueezeNet-SSD)
[MobileNetV2-SSDLite](https://github.com/chuanqi305/MobileNetv2-SSDLite)
[MobileNetV3-SSDLite](https://github.com/XiaoyuHuang96/MobilenetV3SSDLite-tfkeras)
...
- 检测:
[Faster-RCNN](https://github.com/rbgirshick/py-faster-rcnn)
[R-FCN](https://github.com/daijifeng001/R-FCN)
...
- 检测:
[YOLOv2](https://github.com/longcw/yolo2-pytorch)
[YOLOv3](https://github.com/ultralytics/yolov3)
[MobileNet-YOLOv3](https://github.com/eric612/MobileNet-YOLO)
[YOLOv4](https://github.com/Tianxiaomo/pytorch-YOLOv4)
[YOLOv5](https://github.com/ultralytics/yolov5)
[YOLOv7](https://github.com/WongKinYiu/yolov7)
[YOLOX](https://github.com/Megvii-BaseDetection/YOLOX)
[YOLOv8](https://github.com/nihui/ncnn-android-yolov8)
...
- 检测:
[NanoDet](https://github.com/RangiLyu/nanodet)
- 分割:
[FCN](https://github.com/unsky/FPN)
[PSPNet](https://github.com/hszhao/PSPNet)
[UNet](https://github.com/zhixuhao/unet)
[YOLACT](https://github.com/dbolya/yolact)
...
- 姿态估计:
[SimplePose](https://github.com/dog-qiuqiu/Ultralight-SimplePose)
...
## 使用指南
**[配合 alexnet 使用 ncnn](https://github.com/Tencent/ncnn/wiki/use-ncnn-with-alexnet) 包含详细步骤,强烈推荐给新手 :)**
**[ncnn 组件使用指北 alexnet](https://github.com/Tencent/ncnn/wiki/use-ncnn-with-alexnet.zh) 附带详细步骤,新人强烈推荐 :)**
**[使用 netron 进行 ncnn 模型可视化](https://netron.app)**
**[配合 pytorch 或 onnx 使用 ncnn](https://github.com/Tencent/ncnn/wiki/use-ncnn-with-pytorch-or-onnx)**
[ncnn 底层操作 API](https://github.com/Tencent/ncnn/wiki/low-level-operation-api)
[ncnn param 和 model 文件规范](https://github.com/Tencent/ncnn/wiki/param-and-model-file-structure)
[ncnn 操作 param weight 表](https://github.com/Tencent/ncnn/wiki/operation-param-weight-table)
[如何逐步实现自定义层](https://github.com/Tencent/ncnn/wiki/how-to-implement-custom-layer-step-by-step)
## 常见问题
**[ncnn deepwiki](https://deepwiki.com/Tencent/ncnn) LLM 问答 ;)**
**[ncnn 抛出错误](https://github.com/Tencent/ncnn/wiki/FAQ-ncnn-throw-error)**
**[ncnn 产生错误结果](https://github.com/Tencent/ncnn/wiki/FAQ-ncnn-produce-wrong-result)**
**[ncnn vulkan](https://github.com/Tencent/ncnn/wiki/FAQ-ncnn-vulkan)**
## 功能特性
- 支持卷积神经网络,支持多输入和多分支结构,可计算部分分支
- 无第三方库依赖,不依赖 BLAS / NNPACK 或任何其他计算框架
- 纯 C++ 实现,跨平台,支持 Android、iOS 等
- ARM NEON 汇编级的精心优化,计算速度极快
- 精细的内存管理和数据结构设计,内存占用极低
- 支持多核并行计算加速,ARM big.LITTLE CPU 调度优化
- 支持通过新一代低开销的 Vulkan API 进行 GPU 加速
- 可扩展的模型设计,支持 8bit [量化](https://github.com/Tencent/ncnn/wiki/quantized-int8-inference) 和半精度浮点存储,可导入 caffe/pytorch/mxnet/onnx/darknet/keras/tensorflow(mlir) 模型
- 支持直接内存零拷贝引用加载网络模型
- 可注册自定义层实现并扩展
- 嗯,很强,不怕被塞卷 QvQ
## 功能概述
- 支持卷积神经网络,支持多输入和多分支结构,可计算部分分支
- 无任何第三方库依赖,不依赖 BLAS/NNPACK 等计算框架
- 纯 C++ 实现,跨平台,支持 Android / iOS 等
- ARM Neon 汇编级良心优化,计算速度极快
- 精细的内存管理和数据结构设计,内存占用极低
- 支持多核并行计算加速,ARM big.LITTLE CPU 调度优化
- 支持基于全新低消耗的 Vulkan API GPU 加速
- 可扩展的模型设计,支持 8bit [量化](tools/quantize) 和半精度浮点存储,可导入 caffe/pytorch/mxnet/onnx/darknet/keras/tensorflow(mlir) 模型
- 支持直接内存零拷贝引用加载网络模型
- 可注册自定义层实现并扩展
- 恩,很强就是了,不怕被塞卷 QvQ
## 支持的平台矩阵
- ✅ = 已知可工作且经过良好优化运行极快
- ✔️ = 已知可工作,但速度可能不够快
- ❔ = 应该可以工作,但未确认
- / = 不适用
| | Windows | Linux | Android | macOS | iOS |
| ---------- | ------- | ----- | ------- | ----- | --- |
| intel-cpu | ✔️ | ✔️ | ✔️ | ✔️ | / |
| intel-gpu | ✔️ | ✔️ | ✔️ | ✔️ | / |
| amd-cpu | ✔️ | ✔️ | ✔️ | ✔️ | / |
| amd-gpu | ✔️ | ✔️ | ✔️ | ✔️ | / |
| nvidia-gpu | ✔️ | ✔️ | ✔️ | ✔️ | / |
| qcom-cpu | ✅ | ✅ | ✅ | / | / |
| qcom-gpu | ✔️ | ✔️ | ✔️ | / | / |
| arm-cpu | ✅ | ✅ | ✅ | / | / |
| arm-gpu | ❔ | ✔️ | ✔️ | / | / |
| apple-cpu | / | / | / | ✔️ | ✅ |
| apple-gpu | / | / | / | ✔️ | ✔️ |
| ibm-cpu | / | ✔️ | / | / | / |
## 项目示例
-
-
-
-
-
-
- 🤩
-






-
- 从 Fortran 调用 ncnn
- 使用 ncnn 进行实时语音
识别 (即语音转文本);同时支持嵌入式设备并提供
移动端应用 (如 Android App)
## 开源许可
[BSD 3 Clause](LICENSE.txt)
|
技术交流 QQ 群 637093648 (超多大佬) 答案:卷卷卷卷卷(已满) |
Telegram Group
|
Discord Channel
|
|
Pocky QQ 群(MLIR YES!) 677104663 (超多大佬) 答案:multi-level intermediate representation |
||
|
他们都不知道 pnnx 有多好用群 818998520 (新群!) |
|
**[如何在 Linux / Windows / macOS / Raspberry Pi3, Pi4 / POWER / Android / NVIDIA Jetson / iOS / WebAssembly / AllWinner D1 / Loongson 2K1000 上构建 ncnn 库](https://github.com/Tencent/ncnn/wiki/how-to-build)** | ||
| Source |
[ |
||
|
- [为 Android 构建](https://github.com/Tencent/ncnn/wiki/how-to-build#build-for-android) - [在 Android 的 Termux 上构建](https://github.com/Tencent/ncnn/wiki/how-to-build#build-for-termux-on-android) | ||
| Android |
[ |
[ |
|
| Android shared |
[ |
||
|
|
- [通过交叉编译为 HarmonyOS 构建](https://github.com/Tencent/ncnn/wiki/how-to-build#build-for-harmonyos-with-cross-compiling) | ||
| HarmonyOS |
[ |
||
| HarmonyOS shared | |||
|
- [在 macOS 上使用 xcode 为 iOS 构建](https://github.com/Tencent/ncnn/wiki/how-to-build#build-for-ios-on-macos-with-xcode) | ||
| iOS |
[ |
[ |
|
| iOS-Simulator |
[ |
||
|
- [为 macOS 构建](https://github.com/Tencent/ncnn/wiki/how-to-build#build-for-macos) | ||
| macOS |
[ |
[ |
|
| Mac-Catalyst |
[ |
[ |
|
| watchOS |
[ |
[ |
|
| watchOS-Simulator |
[ |
||
| tvOS |
[ |
[ |
|
| tvOS-Simulator |
[ |
||
| visionOS |
[ |
[ |
|
| visionOS-Simulator |
[ |
||
| Apple xcframework |
[ |
||
|
- [为 Linux / NVIDIA Jetson / Raspberry Pi3, Pi4 / POWER 构建](https://github.com/Tencent/ncnn/wiki/how-to-build#build-for-linux) | ||
| Ubuntu 22.04 |
[ |
[ |
|
| Ubuntu 24.04 |
[ |
||
|
- [使用 VS2017 为 Windows x64 构建](https://github.com/Tencent/ncnn/wiki/how-to-build#build-for-windows-x64-using-visual-studio-community-2017) - [使用 MinGW-w64 为 Windows x64 构建](https://github.com/Tencent/ncnn/wiki/how-to-build#build-for-windows-x64-using-mingw-w64) | ||
| VS2015 |
[ |
[ |
|
| VS2017 |
[ |
||
| VS2019 |
[ |
||
| VS2022 |
[ |
||
|
- [为 WebAssembly 构建](https://github.com/Tencent/ncnn/wiki/how-to-build#build-for-webassembly) | ||
| WebAssembly |
[ |
[ |
|
|
- [通过交叉编译为 ARM Cortex-A 系列构建](https://github.com/Tencent/ncnn/wiki/how-to-build#build-for-arm-cortex-a-family-with-cross-compiling) - [通过交叉编译为 Hisilicon 平台构建](https://github.com/Tencent/ncnn/wiki/how-to-build#build-for-hisilicon-platform-with-cross-compiling) - [为 AllWinner D1 构建](https://github.com/Tencent/ncnn/wiki/how-to-build#build-for-allwinner-d1) - [为 Loongson 2K1000 构建](https://github.com/Tencent/ncnn/wiki/how-to-build#build-for-loongson-2k1000) - [为 QNX 构建](https://github.com/Tencent/ncnn/wiki/how-to-build#build-for-qnx) | ||
| Linux (arm) |
[ |
||
| Linux (aarch64) |
[ |
||
| Linux (mips) |
[ |
||
| Linux (mips64) |
[ |
||
| Linux (ppc64) |
[ |
||
| Linux (riscv64) |
[ |
||
| Linux (loongarch64) |
[ |
||






-
- 标签:AI部署, Apex, C++, CNCF毕业项目, NPU, 人工智能, 凭据扫描, 前向计算, 图像处理, 开源框架, 持续集成, 推理框架, 数据擦除, 机器学习, 模型优化, 深度学习, 用户模式Hook绕过, 神经网络, 移动端, 端侧AI, 算法移植, 腾讯, 计算机视觉, 边缘计算, 高性能计算