Elffuss BraidHub

kikocis/ncnn public

master · 3.2 KiBRenderedRawPermalink
1# ncnn
2python wrapper of ncnn with [pybind11](https://github.com/pybind/pybind11), only support python3.x now.
3
4
5Install from pip
6==================
7
8ncnn is available as wheel packages for macOS, Windows and Linux distributions, you can install with pip:
9
10```
11python -m pip install -U pip
12python -m pip install -U ncnn
13```
14
15# Build from source
16
17If 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.
18
19## Prerequisites
20
21**On Unix (Linux, OS X)**
22
23* A compiler with C++11 support
24* CMake >= 3.4
25
26**On Mac**
27
28* A compiler with C++11 support
29* CMake >= 3.4
30
31**On Windows**
32
33* Visual Studio 2015 or higher
34* CMake >= 3.4
35
36## Build & Install
37
381. clone ncnn and init submodule.
39
40```bash
41cd /pathto/ncnn
42git submodule init && git submodule update
43```
44
452. build and install.
46
47```
48python setup.py install
49```
50
51If you want to use a custom toolchain, you can install with the `CMAKE_TOOLCHAIN_FILE` environment variable, like this:
52
53```
54CMAKE_TOOLCHAIN_FILE="../../toolchains/power9le-linux-gnu-vsx.clang.toolchain.cmake" python setup.py install
55```
56
57if you want to enable the usage of vulkan, you can install as following:
58
59```
60python setup.py install --vulkan=on
61```
62
63> **Attention:**
64>
65> To enable Vulkan support, you must first install the Vulkan SDK.
66>
67> **For Windows or Linux Users:**
68>
69> Ensure that the `VULKAN_SDK` environment variable is set to the path of the Vulkan SDK.
70>
71> **For MacOS Users:**
72>
73> 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](https://github.com/Tencent/ncnn/blob/master/.github/workflows/release-python.yml).
74
75## Custom-build & Install
76
771. clone ncnn and init submodule.
78```bash
79cd /pathto/ncnn
80git submodule init && git submodule update
81```
822. build.
83```bash
84mkdir build
85cd build
86cmake -DNCNN_PYTHON=ON ..
87make
88```
89
903. install
91
92```bash
93cd /pathto/ncnn
94pip install .
95```
96
97if you use conda or miniconda, you can also install as following:
98```bash
99cd /pathto/ncnn
100python3 setup.py install
101```
102
103## Tests
104
105**test**
106```bash
107cd /pathto/ncnn/python
108python3 tests/test.py
109```
110
111**benchmark**
112
113```bash
114cd /pathto/ncnn/python
115python3 tests/benchmark.py
116```
117
118## Numpy
119**ncnn.Mat->numpy.array, with no memory copy**
120
121```bash
122mat = ncnn.Mat(...)
123mat_np = np.array(mat)
124```
125
126**numpy.array->ncnn.Mat, with no memory copy**
127```bash
128mat_np = np.array(...)
129mat = ncnn.Mat(mat_np)
130```
131
132# Model Zoo
133install requirements
134```bash
135pip install -r requirements.txt
136```
137then you can import ncnn.model_zoo and get model list as follow:
138```bash
139import ncnn
140import ncnn.model_zoo as model_zoo
141
142print(model_zoo.get_model_list())
143```
144models now in model zoo are as list below:
145```bash
146mobilenet_yolov2
147mobilenetv2_yolov3
148yolov4_tiny
149yolov4
150yolov5s
151yolact
152mobilenet_ssd
153squeezenet_ssd
154mobilenetv2_ssdlite
155mobilenetv3_ssdlite
156squeezenet
157faster_rcnn
158peleenet_ssd
159retinaface
160rfcn
161shufflenetv2
162simplepose
163nanodet
164```
165all model in model zoo has example in ncnn/python/examples folder
166
167# Custom Layer
168
169custom layer demo is in ncnn/python/ncnn/model_zoo/yolov5.py:23