| 1 | # ncnn |
| 2 | python wrapper of ncnn with [pybind11](https://github.com/pybind/pybind11), only support python3.x now. |
| 3 | |
| 4 | |
| 5 | Install from pip |
| 6 | ================== |
| 7 | |
| 8 | ncnn is available as wheel packages for macOS, Windows and Linux distributions, you can install with pip: |
| 9 | |
| 10 | ``` |
| 11 | python -m pip install -U pip |
| 12 | python -m pip install -U ncnn |
| 13 | ``` |
| 14 | |
| 15 | # Build from source |
| 16 | |
| 17 | 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. |
| 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 | |
| 38 | 1. clone ncnn and init submodule. |
| 39 | |
| 40 | ```bash |
| 41 | cd /pathto/ncnn |
| 42 | git submodule init && git submodule update |
| 43 | ``` |
| 44 | |
| 45 | 2. build and install. |
| 46 | |
| 47 | ``` |
| 48 | python setup.py install |
| 49 | ``` |
| 50 | |
| 51 | If you want to use a custom toolchain, you can install with the `CMAKE_TOOLCHAIN_FILE` environment variable, like this: |
| 52 | |
| 53 | ``` |
| 54 | CMAKE_TOOLCHAIN_FILE="../../toolchains/power9le-linux-gnu-vsx.clang.toolchain.cmake" python setup.py install |
| 55 | ``` |
| 56 | |
| 57 | if you want to enable the usage of vulkan, you can install as following: |
| 58 | |
| 59 | ``` |
| 60 | python 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 | |
| 77 | 1. clone ncnn and init submodule. |
| 78 | ```bash |
| 79 | cd /pathto/ncnn |
| 80 | git submodule init && git submodule update |
| 81 | ``` |
| 82 | 2. build. |
| 83 | ```bash |
| 84 | mkdir build |
| 85 | cd build |
| 86 | cmake -DNCNN_PYTHON=ON .. |
| 87 | make |
| 88 | ``` |
| 89 | |
| 90 | 3. install |
| 91 | |
| 92 | ```bash |
| 93 | cd /pathto/ncnn |
| 94 | pip install . |
| 95 | ``` |
| 96 | |
| 97 | if you use conda or miniconda, you can also install as following: |
| 98 | ```bash |
| 99 | cd /pathto/ncnn |
| 100 | python3 setup.py install |
| 101 | ``` |
| 102 | |
| 103 | ## Tests |
| 104 | |
| 105 | **test** |
| 106 | ```bash |
| 107 | cd /pathto/ncnn/python |
| 108 | python3 tests/test.py |
| 109 | ``` |
| 110 | |
| 111 | **benchmark** |
| 112 | |
| 113 | ```bash |
| 114 | cd /pathto/ncnn/python |
| 115 | python3 tests/benchmark.py |
| 116 | ``` |
| 117 | |
| 118 | ## Numpy |
| 119 | **ncnn.Mat->numpy.array, with no memory copy** |
| 120 | |
| 121 | ```bash |
| 122 | mat = ncnn.Mat(...) |
| 123 | mat_np = np.array(mat) |
| 124 | ``` |
| 125 | |
| 126 | **numpy.array->ncnn.Mat, with no memory copy** |
| 127 | ```bash |
| 128 | mat_np = np.array(...) |
| 129 | mat = ncnn.Mat(mat_np) |
| 130 | ``` |
| 131 | |
| 132 | # Model Zoo |
| 133 | install requirements |
| 134 | ```bash |
| 135 | pip install -r requirements.txt |
| 136 | ``` |
| 137 | then you can import ncnn.model_zoo and get model list as follow: |
| 138 | ```bash |
| 139 | import ncnn |
| 140 | import ncnn.model_zoo as model_zoo |
| 141 | |
| 142 | print(model_zoo.get_model_list()) |
| 143 | ``` |
| 144 | models now in model zoo are as list below: |
| 145 | ```bash |
| 146 | mobilenet_yolov2 |
| 147 | mobilenetv2_yolov3 |
| 148 | yolov4_tiny |
| 149 | yolov4 |
| 150 | yolov5s |
| 151 | yolact |
| 152 | mobilenet_ssd |
| 153 | squeezenet_ssd |
| 154 | mobilenetv2_ssdlite |
| 155 | mobilenetv3_ssdlite |
| 156 | squeezenet |
| 157 | faster_rcnn |
| 158 | peleenet_ssd |
| 159 | retinaface |
| 160 | rfcn |
| 161 | shufflenetv2 |
| 162 | simplepose |
| 163 | nanodet |
| 164 | ``` |
| 165 | all model in model zoo has example in ncnn/python/examples folder |
| 166 | |
| 167 | # Custom Layer |
| 168 | |
| 169 | custom layer demo is in ncnn/python/ncnn/model_zoo/yolov5.py:23 |