# ncnn **Repository Path**: Tencent/ncnn ## Basic Information - **Project Name**: ncnn - **Description**: ncnn ncnn 是腾讯优图实验室首个开源项目,是一个为手机端极致优化的高性能神经网络前向计算框架 - **Primary Language**: C/C++ - **License**: BSD-3-Clause - **Default Branch**: master - **Homepage**: https://www.oschina.net/p/ncnn - **GVP Project**: No ## Statistics - **Stars**: 301 - **Forks**: 3 - **Created**: 2017-07-24 - **Last Updated**: 2026-05-25 ## Categories & Tags **Categories**: ai **Tags**: None ## README ![ncnn](https://raw.githubusercontent.com/Tencent/ncnn/master/images/256-ncnn.png) # ncnn [![License](https://img.shields.io/badge/license-BSD_3_Clause-blue.svg?style=for-the-badge)](LICENSE.txt) [![Download Total Count](https://img.shields.io/github/downloads/Tencent/ncnn/total.svg?style=for-the-badge)](https://github.com/Tencent/ncnn/releases) [![codecov](https://img.shields.io/codecov/c/github/Tencent/ncnn/master?style=for-the-badge)](https://codecov.io/gh/Tencent/ncnn) ncnn is a high-performance neural network inference framework optimized for mobile, embedded, and desktop deployment. It has no third-party runtime dependencies, runs across CPU and Vulkan GPU backends, and provides tools such as pnnx for converting PyTorch and ONNX models to ncnn. Developers can deploy deep learning models efficiently on phones, PCs, browsers, and edge devices. ncnn is currently being used in many Tencent applications, such as QQ, Qzone, WeChat, Pitu, and so on. ncnn 是一个面向移动端、嵌入式和桌面端部署优化的高性能神经网络推理框架。 ncnn 无第三方运行时依赖,支持 CPU 和 Vulkan GPU 后端,并提供 pnnx 等工具将 PyTorch 和 ONNX 模型转换为 ncnn 模型。 基于 ncnn,开发者可以将深度学习模型高效部署到手机、PC、浏览器和边缘设备上。 ncnn 目前已在腾讯多款应用中使用,如:QQ,Qzone,微信,天天 P 图等。 --- ## Quick Start The recommended beginner path is PyTorch -> pnnx -> ncnn.
**Install pnnx in a PyTorch environment** ```shell pip3 install pnnx ``` **Export a PyTorch model to ncnn** ```python import torch import torch.nn as nn import pnnx class Model(nn.Module): def __init__(self): super().__init__() self.conv = nn.Conv2d(3, 8, 1) self.relu = nn.ReLU() self.fc = nn.Linear(8, 4) def forward(self, x): x = self.conv(x) x = self.relu(x) x = x.mean((2, 3)) return self.fc(x) model = Model().eval() x = torch.rand(1, 3, 224, 224) pnnx.export(model, "model.pt", (x,)) ``` This generates `model.ncnn.param` and `model.ncnn.bin`. **Run with ncnn C++ API** ```cpp #include "net.h" ncnn::Net net; net.load_param("model.ncnn.param"); net.load_model("model.ncnn.bin"); ncnn::Mat in(224, 224, 3); auto ex = net.create_extractor(); ex.input("in0", in); ncnn::Mat out; ex.extract("out0", out); ``` **Or use Python** ```python import numpy as np import ncnn net = ncnn.Net() net.load_param("model.ncnn.param") net.load_model("model.ncnn.bin") x = np.zeros((3, 224, 224), np.float32) mat = ncnn.Mat(x) ex = net.create_extractor() ex.input("in0", mat) ret, out = ex.extract("out0") print(np.array(out).shape) ```
See [pnnx](tools/pnnx), [use ncnn with PyTorch or ONNX](https://github.com/Tencent/ncnn/wiki/use-ncnn-with-pytorch-or-onnx), [Python API](python), and [examples](examples) for complete workflows. --- ## Community
技术交流 QQ 群
637093648 (超多大佬)
答案:卷卷卷卷卷(已满)
Telegram Group Discord Channel
Pocky QQ 群(MLIR YES!)
677104663 (超多大佬)
答案:multi-level intermediate representation
他们都不知道 pnnx 有多好用群
818998520 (新群!)
--- ## Download & Build status https://github.com/Tencent/ncnn/releases/latest
**[how to build ncnn library](https://github.com/Tencent/ncnn/wiki/how-to-build) on Linux / Windows / macOS / Raspberry Pi3, Pi4 / POWER / Android / NVIDIA Jetson / iOS / WebAssembly / AllWinner D1 / Loongson 2K1000**
Source [](https://github.com/Tencent/ncnn/releases/latest/download/ncnn-20260113-full-source.zip)
- [Build for Android](https://github.com/Tencent/ncnn/wiki/how-to-build#build-for-android) - [Build for Termux on Android](https://github.com/Tencent/ncnn/wiki/how-to-build#build-for-termux-on-android)
Android [](https://github.com/Tencent/ncnn/releases/latest/download/ncnn-20260113-android-vulkan.zip) [](https://github.com/Tencent/ncnn/releases/latest/download/ncnn-20260113-android.zip) [](https://github.com/Tencent/ncnn/actions?query=workflow%3Aandroid)
Android shared [](https://github.com/Tencent/ncnn/releases/latest/download/ncnn-20260113-android-vulkan-shared.zip) [](https://github.com/Tencent/ncnn/releases/latest/download/ncnn-20260113-android-shared.zip)
- [Build for HarmonyOS with cross-compiling](https://github.com/Tencent/ncnn/wiki/how-to-build#build-for-harmonyos-with-cross-compiling)
HarmonyOS [](https://github.com/Tencent/ncnn/actions?query=workflow%3Aharmonyos)
HarmonyOS shared
- [Build for iOS on macOS with xcode](https://github.com/Tencent/ncnn/wiki/how-to-build#build-for-ios-on-macos-with-xcode)
iOS [](https://github.com/Tencent/ncnn/releases/latest/download/ncnn-20260113-ios-vulkan.zip) [](https://github.com/Tencent/ncnn/releases/latest/download/ncnn-20260113-ios.zip) [](https://github.com/Tencent/ncnn/actions?query=workflow%3Aios)
iOS-Simulator [](https://github.com/Tencent/ncnn/releases/latest/download/ncnn-20260113-ios-simulator-vulkan.zip) [](https://github.com/Tencent/ncnn/releases/latest/download/ncnn-20260113-ios-simulator.zip)
- [Build for macOS](https://github.com/Tencent/ncnn/wiki/how-to-build#build-for-macos)
macOS [](https://github.com/Tencent/ncnn/releases/latest/download/ncnn-20260113-macos-vulkan.zip) [](https://github.com/Tencent/ncnn/releases/latest/download/ncnn-20260113-macos.zip) [](https://github.com/Tencent/ncnn/actions?query=workflow%3Amacos)
Mac-Catalyst [](https://github.com/Tencent/ncnn/releases/latest/download/ncnn-20260113-mac-catalyst-vulkan.zip) [](https://github.com/Tencent/ncnn/releases/latest/download/ncnn-20260113-mac-catalyst.zip) [](https://github.com/Tencent/ncnn/actions?query=workflow%3Amac-catalyst)
watchOS [](https://github.com/Tencent/ncnn/releases/latest/download/ncnn-20260113-watchos.zip) [](https://github.com/Tencent/ncnn/actions?query=workflow%3Awatchos)
watchOS-Simulator [](https://github.com/Tencent/ncnn/releases/latest/download/ncnn-20260113-watchos-simulator.zip)
tvOS [](https://github.com/Tencent/ncnn/releases/latest/download/ncnn-20260113-tvos-vulkan.zip) [](https://github.com/Tencent/ncnn/releases/latest/download/ncnn-20260113-tvos.zip) [](https://github.com/Tencent/ncnn/actions?query=workflow%3Atvos)
tvOS-Simulator [](https://github.com/Tencent/ncnn/releases/latest/download/ncnn-20260113-tvos-simulator-vulkan.zip) [](https://github.com/Tencent/ncnn/releases/latest/download/ncnn-20260113-tvos-simulator.zip)
visionOS [](https://github.com/Tencent/ncnn/releases/latest/download/ncnn-20260113-visionos-vulkan.zip) [](https://github.com/Tencent/ncnn/releases/latest/download/ncnn-20260113-visionos.zip) [](https://github.com/Tencent/ncnn/actions?query=workflow%3Avisionos)
visionOS-Simulator [](https://github.com/Tencent/ncnn/releases/latest/download/ncnn-20260113-visionos-simulator-vulkan.zip) [](https://github.com/Tencent/ncnn/releases/latest/download/ncnn-20260113-visionos-simulator.zip)
Apple xcframework [](https://github.com/Tencent/ncnn/releases/latest/download/ncnn-20260113-apple-vulkan.zip) [](https://github.com/Tencent/ncnn/releases/latest/download/ncnn-20260113-apple.zip)
- [Build for Linux / NVIDIA Jetson / Raspberry Pi3, Pi4 / POWER](https://github.com/Tencent/ncnn/wiki/how-to-build#build-for-linux)
Ubuntu 22.04 [](https://github.com/Tencent/ncnn/releases/latest/download/ncnn-20260113-ubuntu-2204.zip) [](https://github.com/Tencent/ncnn/releases/latest/download/ncnn-20260113-ubuntu-2204-shared.zip) [](https://github.com/Tencent/ncnn/actions?query=workflow%3Alinux-x64-gpu-gcc)
Ubuntu 24.04 [](https://github.com/Tencent/ncnn/releases/latest/download/ncnn-20260113-ubuntu-2404.zip) [](https://github.com/Tencent/ncnn/releases/latest/download/ncnn-20260113-ubuntu-2404-shared.zip)
windows - [Build for Windows x64 using VS2017](https://github.com/Tencent/ncnn/wiki/how-to-build#build-for-windows-x64-using-visual-studio-community-2017) - [Build for Windows x64 using MinGW-w64](https://github.com/Tencent/ncnn/wiki/how-to-build#build-for-windows-x64-using-mingw-w64)
VS2015 [](https://github.com/Tencent/ncnn/releases/latest/download/ncnn-20260113-windows-vs2015.zip) [](https://github.com/Tencent/ncnn/releases/latest/download/ncnn-20260113-windows-vs2015-shared.zip) [](https://github.com/Tencent/ncnn/actions?query=workflow%3Awindows)
VS2017 [](https://github.com/Tencent/ncnn/releases/latest/download/ncnn-20260113-windows-vs2017.zip) [](https://github.com/Tencent/ncnn/releases/latest/download/ncnn-20260113-windows-vs2017-shared.zip)
VS2019 [](https://github.com/Tencent/ncnn/releases/latest/download/ncnn-20260113-windows-vs2019.zip) [](https://github.com/Tencent/ncnn/releases/latest/download/ncnn-20260113-windows-vs2019-shared.zip)
VS2022 [](https://github.com/Tencent/ncnn/releases/latest/download/ncnn-20260113-windows-vs2022.zip) [](https://github.com/Tencent/ncnn/releases/latest/download/ncnn-20260113-windows-vs2022-shared.zip)
- [Build for WebAssembly](https://github.com/Tencent/ncnn/wiki/how-to-build#build-for-webassembly)
WebAssembly [](https://github.com/Tencent/ncnn/releases/latest/download/ncnn-20260113-webassembly.zip) [](https://github.com/Tencent/ncnn/actions?query=workflow%3Aweb-assembly)
- [Build for ARM Cortex-A family with cross-compiling](https://github.com/Tencent/ncnn/wiki/how-to-build#build-for-arm-cortex-a-family-with-cross-compiling) - [Build for Hisilicon platform with cross-compiling](https://github.com/Tencent/ncnn/wiki/how-to-build#build-for-hisilicon-platform-with-cross-compiling) - [Build for AllWinner D1](https://github.com/Tencent/ncnn/wiki/how-to-build#build-for-allwinner-d1) - [Build for Loongson 2K1000](https://github.com/Tencent/ncnn/wiki/how-to-build#build-for-loongson-2k1000) - [Build for QNX](https://github.com/Tencent/ncnn/wiki/how-to-build#build-for-qnx)
Linux (arm) [](https://github.com/Tencent/ncnn/actions?query=workflow%3Alinux-arm)
Linux (aarch64) [](https://github.com/Tencent/ncnn/actions?query=workflow%3Alinux-aarch64)
Linux (mips) [](https://github.com/Tencent/ncnn/actions?query=workflow%3Alinux-mips)
Linux (mips64) [](https://github.com/Tencent/ncnn/actions?query=workflow%3Alinux-mips64)
Linux (ppc64) [](https://github.com/Tencent/ncnn/actions?query=workflow%3Alinux-ppc64)
Linux (riscv64) [](https://github.com/Tencent/ncnn/actions?query=workflow%3Alinux-riscv64)
Linux (loongarch64) [](https://github.com/Tencent/ncnn/actions?query=workflow%3Alinux-loongarch64)
--- ## Build Use the prebuilt packages above when possible. To build from source, see the full [how to build ncnn library](https://github.com/Tencent/ncnn/wiki/how-to-build) guide for Linux, Windows, macOS, Android, iOS, WebAssembly, HarmonyOS, Raspberry Pi, Jetson, and embedded targets. Common Linux build: ```bash git clone --recursive https://github.com/Tencent/ncnn.git cd ncnn mkdir build && cd build cmake -DCMAKE_BUILD_TYPE=Release -DNCNN_VULKAN=ON -DNCNN_BUILD_EXAMPLES=ON .. cmake --build . -j$(nproc) ``` --- ## Model Conversion | Source model | Recommended path | Docs | | --- | --- | --- | | PyTorch | `pnnx.export(model, "model.pt", (input_tensor,))` or `pnnx model.pt inputshape=[...]` | [pnnx](tools/pnnx), [PyTorch / ONNX guide](https://github.com/Tencent/ncnn/wiki/use-ncnn-with-pytorch-or-onnx) | | ONNX | `pnnx model.onnx` | [pnnx](tools/pnnx), [onnx tools](tools/onnx) | | ncnn model optimization | `ncnnoptimize model.param model.bin new.param new.bin flag` | [quantization](tools/quantize), [model file spec](https://github.com/Tencent/ncnn/wiki/param-and-model-file-structure) | | Legacy Caffe / MXNet / Darknet | Use compatibility converters when maintaining older models | [caffe](tools/caffe), [mxnet](tools/mxnet), [darknet](tools/darknet), [AlexNet legacy tutorial](https://github.com/Tencent/ncnn/wiki/use-ncnn-with-alexnet) | Use [Netron](https://netron.app) to inspect `.param`, `.onnx`, and `.pnnx.param` graphs. --- ## Features - No third-party runtime dependencies and no BLAS / NNPACK requirement. - Pure C++ implementation with C API and Python binding. - Optimized CPU inference for mobile and embedded processors, including ARM NEON and multi-core scheduling. - Vulkan GPU acceleration for supported platforms. - Low memory footprint with explicit blob/workspace allocator design. - Supports multi-input, multi-output, and multi-branch graphs. - PyTorch and ONNX conversion through pnnx, plus legacy converter support for older model formats. - Supports fp16 storage/arithmetic paths, int8 quantized inference, model optimization, and custom layers. - Direct memory reference loading for `.param` and `.bin` models. --- ## Model and Workload Coverage ncnn is still strong for classic and mobile CNN workloads, but current usage is broader than CNN-only deployment. - Classification and backbones: [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, [ResNet](https://github.com/tornadomeet/ResNet), [DenseNet](https://github.com/liuzhuang13/DenseNet), [SENet](https://github.com/hujie-frank/SENet), [SqueezeNet](https://github.com/forresti/SqueezeNet), MobileNet, ShuffleNet, MNasNet. - Detection and face: SSD, Faster R-CNN, R-FCN, [MTCNN](https://github.com/ipazc/mtcnn), [RetinaFace](https://github.com/biubug6/Pytorch_Retinaface), [scrfd](https://github.com/nihui/ncnn-android-scrfd), [YOLOv2](https://github.com/longcw/yolo2-pytorch), [YOLOv3](https://github.com/ultralytics/yolov3), [YOLOv4](https://github.com/Tianxiaomo/pytorch-YOLOv4), [YOLOv5](https://github.com/ultralytics/yolov5), [YOLOv7](https://github.com/WongKinYiu/yolov7), [YOLOv8](https://github.com/nihui/ncnn-android-yolov8), [YOLOX](https://github.com/Megvii-BaseDetection/YOLOX), [NanoDet](https://github.com/RangiLyu/nanodet). - Segmentation, pose, and OCR: FCN, [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), PP-OCR examples. - Audio, generation, and language workloads are represented by community projects and examples where the model operators are supported. For operator-level detail, see [supported PyTorch operator status](tools/pnnx#supported-pytorch-operator-status), [supported ONNX operator status](tools/pnnx#supported-onnx-operator-status), and [operation param weight table](https://github.com/Tencent/ncnn/wiki/operation-param-weight-table). --- ## Project Examples | Area | Project | | --- | --- | | Image generation | [zimage-ncnn-vulkan](https://github.com/nihui/zimage-ncnn-vulkan) - Z-Image generation with ncnn and Vulkan | | LLM / embedding / vision-language | [ncnn_llm](https://github.com/futz12/ncnn_llm) - LLM, embedding, and vision-language examples with ncnn | | Android classification | [ncnn-android-squeezenet](https://github.com/nihui/ncnn-android-squeezenet) | | Android style transfer | [ncnn-android-styletransfer](https://github.com/nihui/ncnn-android-styletransfer) | | Android detection | [ncnn-android-mobilenetssd](https://github.com/nihui/ncnn-android-mobilenetssd), [ncnn-android-yolov5](https://github.com/nihui/ncnn-android-yolov5), [ncnn-android-yolov7](https://github.com/xiang-wuu/ncnn-android-yolov7), [ncnn-android-scrfd](https://github.com/nihui/ncnn-android-scrfd) | | Face detection | [mtcnn_ncnn](https://github.com/moli232777144/mtcnn_ncnn) | | Qt / Android integration | [qt_android_ncnn_lib_encrypt_example](https://github.com/shaoshengsong/qt_android_ncnn_lib_encrypt_example) | | Colorization | [ncnn-colorization-siggraph17](https://github.com/magicse/ncnn-colorization-siggraph17) | | Fortran binding | [ncnn-fortran](https://github.com/mizu-bai/ncnn-fortran) | | Speech recognition | [sherpa](https://github.com/k2-fsa/sherpa) - real-time speech recognition on embedded and mobile devices | --- ## Documentation And FAQ | Topic | Links | | --- | --- | | Build | [how to build](https://github.com/Tencent/ncnn/wiki/how-to-build) | | PyTorch / ONNX conversion | [use ncnn with PyTorch or ONNX](https://github.com/Tencent/ncnn/wiki/use-ncnn-with-pytorch-or-onnx), [pnnx](tools/pnnx), [PyTorch converter notes](tools/pytorch) | | API and examples | [C++ examples](examples), [Python API](python), [low-level operation API](https://github.com/Tencent/ncnn/wiki/low-level-operation-api) | | Model format | [param and model file spec](https://github.com/Tencent/ncnn/wiki/param-and-model-file-structure), [operation param weight table](https://github.com/Tencent/ncnn/wiki/operation-param-weight-table) | | Extension | [custom layer guide](https://github.com/Tencent/ncnn/wiki/how-to-implement-custom-layer-step-by-step), [plugin tools](tools/plugin) | | FAQ | [deepwiki](https://deepwiki.com/Tencent/ncnn), [throw error](https://github.com/Tencent/ncnn/wiki/FAQ-ncnn-throw-error), [wrong result](https://github.com/Tencent/ncnn/wiki/FAQ-ncnn-produce-wrong-result), [Vulkan](https://github.com/Tencent/ncnn/wiki/FAQ-ncnn-vulkan) | | Legacy beginner material | [use ncnn with AlexNet](https://github.com/Tencent/ncnn/wiki/use-ncnn-with-alexnet), [AlexNet Chinese tutorial](https://github.com/Tencent/ncnn/wiki/use-ncnn-with-alexnet.zh) | --- ## License [BSD 3 Clause](LICENSE.txt)