ncnn is a high-performance neural network inference framework optimized for the mobile platform
Project description
ncnn
python wrapper of ncnn with pybind11, only support python3.x now.
Install from pip
ncnn is available as wheel packages for macOS, Windows and Linux distributions, you can install with pip:
python -m pip install -U pip
python -m pip install -U ncnn
Build from source
If you want to build ncnn with some options not as default, or just like to build everything yourself, it is not difficult to build ncnn from source.
Prerequisites
On Unix (Linux, OS X)
- A compiler with C++11 support
- CMake >= 3.4
On Mac
- A compiler with C++11 support
- CMake >= 3.4
On Windows
- Visual Studio 2015 or higher
- CMake >= 3.4
Build & Install
- clone ncnn and init submodule.
cd /pathto/ncnn
git submodule init && git submodule update
- build and install.
python setup.py install
If you want to use a custom toolchain, you can install with the CMAKE_TOOLCHAIN_FILE environment variable, like this:
CMAKE_TOOLCHAIN_FILE="../../toolchains/power9le-linux-gnu-vsx.clang.toolchain.cmake" python setup.py install
if you want to enable the usage of vulkan, you can install as following:
python setup.py install --vulkan=on
Attention:
To enable Vulkan support, you must first install the Vulkan SDK.
For Windows or Linux Users:
Ensure that the
VULKAN_SDKenvironment variable is set to the path of the Vulkan SDK.For MacOS Users:
On MacOS, you will need to specify additional environment variables. For guidance on setting these variables, please refer to lines 279-286 in the following file: ncnn/.github/workflows/release-python.yml at master · Tencent/ncnn.
Custom-build & Install
- clone ncnn and init submodule.
cd /pathto/ncnn
git submodule init && git submodule update
- build.
mkdir build
cd build
cmake -DNCNN_PYTHON=ON ..
make
- install
cd /pathto/ncnn
pip install .
if you use conda or miniconda, you can also install as following:
cd /pathto/ncnn
python3 setup.py install
Tests
test
cd /pathto/ncnn/python
python3 tests/test.py
benchmark
cd /pathto/ncnn/python
python3 tests/benchmark.py
Numpy
ncnn.Mat->numpy.array, with no memory copy
mat = ncnn.Mat(...)
mat_np = np.array(mat)
numpy.array->ncnn.Mat, with no memory copy
mat_np = np.array(...)
mat = ncnn.Mat(mat_np)
Model Zoo
install requirements
pip install -r requirements.txt
then you can import ncnn.model_zoo and get model list as follow:
import ncnn
import ncnn.model_zoo as model_zoo
print(model_zoo.get_model_list())
models now in model zoo are as list below:
mobilenet_yolov2
mobilenetv2_yolov3
yolov4_tiny
yolov4
yolov5s
yolact
mobilenet_ssd
squeezenet_ssd
mobilenetv2_ssdlite
mobilenetv3_ssdlite
squeezenet
faster_rcnn
peleenet_ssd
retinaface
rfcn
shufflenetv2
simplepose
nanodet
all model in model zoo has example in ncnn/python/examples folder
Custom Layer
custom layer demo is in ncnn/python/ncnn/model_zoo/yolov5.py:23
new
i build the wheel on debian 13 riscv, all test passed. Recommend python version: 3.11 install from pypi~ you can now install direc in riscv machiene!
pip install ncnn-riscv-wheel
# or install from release site! https://github.com/per1cycle/ncnn-riscv-wheel/releases
pip install https://github.com/per1cycle/ncnn-riscv-wheel/releases/download/ncnn-cp311-linux-riscv-wheel/ncnn-1.0.20240704-cp311-cp311-linux_riscv64.whl
Alternative install from source:
apt update
apt install gcc g++ make autoconf automake cmake python3-pip python3-numpy python3-setuptools git vim python3.11-full ninja-build libpython3.11-dev libssl-dev python3-pip python3-setuptools
git clone --recurse-submodules https://github.com/Tencent/ncnn
cd ncnn
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release -DNCNN_BUILD_BENCHMARK=ON -DNCNN_PYTHON=ON -DNCNN_BUILD_TESTS=ON ..
make -j4
cd ..
cd python
python setup.py bdist_wheel
export MAKEFLAGS=-j$(nproc) && python3 -m pip install ncnn-1.0.20240704-cp311-cp311-linux_riscv64.whl --break-system-packages --verbose
# or
pip install dist/<xxx>.whl --break-system-packages
# check if the installation is fine.
pip list | grep ncnn
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file ncnn-riscv-wheel-1.0.20240706.tar.gz.
File metadata
- Download URL: ncnn-riscv-wheel-1.0.20240706.tar.gz
- Upload date:
- Size: 695.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c7da8b937d07f086fb5374c5806e4a59291a1872654fbac78179f1509fc41c7c
|
|
| MD5 |
1e48556fa8707524003a765b384d8b68
|
|
| BLAKE2b-256 |
187b995c1fc9879d527cfe736f3f438bf3ba8317e39077ea95ccbeef39ef47b0
|