Skip to main content

ncnn

ncnn

License Download Total Count codecov

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

pip3 install pnnx

Export a PyTorch model to ncnn

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

#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

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, use ncnn with PyTorch or ONNX, Python API, and examples for complete workflows.


Community

技术交流 QQ 群
637093648 (超多大佬)
答案:卷卷卷卷卷(已满)
Telegram Group

https://t.me/ncnnyes

Discord Channel

https://discord.gg/YRsxgmF

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 on Linux / Windows / macOS / Raspberry Pi3, Pi4 / POWER / Android / NVIDIA Jetson / iOS / WebAssembly / AllWinner D1 / Loongson 2K1000

Source

Android

Android shared

HarmonyOS

HarmonyOS shared

iOS

iOS-Simulator

macOS

Mac-Catalyst

watchOS

watchOS-Simulator

tvOS

tvOS-Simulator

visionOS

visionOS-Simulator

Apple xcframework

Ubuntu 22.04

Ubuntu 24.04

Ubuntu 26.04

windows
VS2015

VS2017

VS2019

VS2022

VS2026

WebAssembly

WebAssembly64

Linux (arm)

Linux (aarch64)

Linux (mips)

Linux (mips64)

Linux (ppc64)

Linux (riscv64)

Linux (loongarch64)


Build

Use the prebuilt packages above when possible. To build from source, see the full how to build ncnn library guide for Linux, Windows, macOS, Android, iOS, WebAssembly, HarmonyOS, Raspberry Pi, Jetson, and embedded targets.

Common Linux build:

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, PyTorch / ONNX guide
ONNX pnnx model.onnx pnnx, onnx tools
ncnn model optimization ncnnoptimize model.param model.bin new.param new.bin flag quantization, model file spec
Legacy Caffe / MXNet / Darknet Use compatibility converters when maintaining older models caffe, mxnet, darknet, AlexNet legacy tutorial

Use Netron 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.

For operator-level detail, see supported PyTorch operator status, supported ONNX operator status, and operation param weight table.


Project Examples

Area Project
Image generation zimage-ncnn-vulkan - Z-Image generation with ncnn and Vulkan
LLM / embedding / vision-language ncnn_llm - LLM, embedding, and vision-language examples with ncnn
Android classification ncnn-android-squeezenet
Android style transfer ncnn-android-styletransfer
Android detection ncnn-android-mobilenetssd, ncnn-android-yolov5, ncnn-android-yolov7, ncnn-android-scrfd
Face detection mtcnn_ncnn
Qt / Android integration qt_android_ncnn_lib_encrypt_example
Colorization ncnn-colorization-siggraph17
Fortran binding ncnn-fortran
Speech recognition sherpa - real-time speech recognition on embedded and mobile devices

Documentation And FAQ

Topic Links
Build how to build
PyTorch / ONNX conversion use ncnn with PyTorch or ONNX, pnnx, PyTorch converter notes
API and examples C++ examples, Python API, low-level operation API
Model format param and model file spec, operation param weight table
Extension custom layer guide, plugin tools
FAQ deepwiki, throw error, wrong result, Vulkan
Legacy beginner material use ncnn with AlexNet, AlexNet Chinese tutorial

License

BSD 3 Clause

Metadata

Release files for ncnn 1.0.20261019

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for ncnn 1.0.20261019
File Actions
ncnn-1.0.20261019-cp315-cp315-win_arm64.whl CPython 3.15 CPython 3.15 Windows ARM64 Details for ncnn-1.0.20261019-cp315-cp315-win_arm64.whl
ncnn-1.0.20261019-cp314-cp314-win_arm64.whl CPython 3.14 CPython 3.14 Windows ARM64 Details for ncnn-1.0.20261019-cp314-cp314-win_arm64.whl
ncnn-1.0.20261019-cp313-cp313-win_arm64.whl CPython 3.13 CPython 3.13 Windows ARM64 Details for ncnn-1.0.20261019-cp313-cp313-win_arm64.whl
ncnn-1.0.20261019-cp312-cp312-win_arm64.whl CPython 3.12 CPython 3.12 Windows ARM64 Details for ncnn-1.0.20261019-cp312-cp312-win_arm64.whl
ncnn-1.0.20261019-cp311-cp311-win_arm64.whl CPython 3.11 CPython 3.11 Windows ARM64 Details for ncnn-1.0.20261019-cp311-cp311-win_arm64.whl
ncnn-1.0.20261019-cp310-cp310-win_arm64.whl CPython 3.10 CPython 3.10 Windows ARM64 Details for ncnn-1.0.20261019-cp310-cp310-win_arm64.whl
ncnn-1.0.20261019-cp39-cp39-win_arm64.whl CPython 3.9 CPython 3.9 Windows ARM64 Details for ncnn-1.0.20261019-cp39-cp39-win_arm64.whl

Total release size: 21.6 MB

Release files / ncnn-1.0.20261019-cp315-cp315-win_arm64.whl

Download URL ncnn-1.0.20261019-cp315-cp315-win_arm64.whl
Size 3.2 MB
Tags CPython 3.15 Windows ARM64
SHA-256 checksum
How to use checksums
9e0d73057de9d51bb7b03ffdbfb8dedb56bee2fb4f01bf66b2564aa5912e9881
BLAKE2b-256 checksum
How to use checksums
985289cafc6487d1d19a39555afbebb68d6ab15153152aa57166df8a086d4041
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / ncnn-1.0.20261019-cp314-cp314-win_arm64.whl

Download URL ncnn-1.0.20261019-cp314-cp314-win_arm64.whl
Size 3.2 MB
Tags CPython 3.14 Windows ARM64
SHA-256 checksum
How to use checksums
21a845c66bc9395eb297d621f369dc854bd5442c6eda492173590693b8ea6d20
BLAKE2b-256 checksum
How to use checksums
65327bca05de626800498227cfb01edd8f97c7859af09ed85c6f901ece778777
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / ncnn-1.0.20261019-cp313-cp313-win_arm64.whl

Download URL ncnn-1.0.20261019-cp313-cp313-win_arm64.whl
Size 3.1 MB
Tags CPython 3.13 Windows ARM64
SHA-256 checksum
How to use checksums
c37dc2fc29bd90ef8d100a548f14cc429917fa13181ce639487d542b40a4d046
BLAKE2b-256 checksum
How to use checksums
cb079c7a91a6a92b1a47d28f56726667cceabee8534427af3bd34b6d091fc990
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / ncnn-1.0.20261019-cp312-cp312-win_arm64.whl

Download URL ncnn-1.0.20261019-cp312-cp312-win_arm64.whl
Size 3.1 MB
Tags CPython 3.12 Windows ARM64
SHA-256 checksum
How to use checksums
b0ff5d1d2acbe5240f5dd59597a67e05d35c0ca4f82c77a9c974a4645b14994d
BLAKE2b-256 checksum
How to use checksums
4509b3c9c88e855497209b4e1df3eecde0bb8c9d0de50b3cbce35575b18d76d6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / ncnn-1.0.20261019-cp311-cp311-win_arm64.whl

Download URL ncnn-1.0.20261019-cp311-cp311-win_arm64.whl
Size 3.0 MB
Tags CPython 3.11 Windows ARM64
SHA-256 checksum
How to use checksums
e37852a78b8017dd22aedefcc8836d82cd0f77e1ee7cec9d0dad79684c72da61
BLAKE2b-256 checksum
How to use checksums
2a15ef83f76d96b260095c0ef39072ad9fced002c8fcbac6b40bac8cd0bfc89b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / ncnn-1.0.20261019-cp310-cp310-win_arm64.whl

Download URL ncnn-1.0.20261019-cp310-cp310-win_arm64.whl
Size 3.0 MB
Tags CPython 3.10 Windows ARM64
SHA-256 checksum
How to use checksums
2f1b19c29c736a35e49bb11ebe79ed760a9677ef7eb6d55c92ec706da17dea6a
BLAKE2b-256 checksum
How to use checksums
2988ae6ccd8e5b55d8437084837e6b79c5bd10508e868aa579fa75f3d2f219dd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / ncnn-1.0.20261019-cp39-cp39-win_arm64.whl

Download URL ncnn-1.0.20261019-cp39-cp39-win_arm64.whl
Size 3.0 MB
Tags CPython 3.9 Windows ARM64
SHA-256 checksum
How to use checksums
2060136165842504a44d1e56020a4683bf4c9a513e499a7c3d4220b44c296f0a
BLAKE2b-256 checksum
How to use checksums
a8fcd578c3d1172735748d6615cc3d6ea1d8ab09e13407bf9276e3cc79278cdf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Security for ncnn 1.0.20261019

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.20261019 This release

7 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page