2022-06-07 18:05:51 +08:00
|
|
|
# ncnn Support
|
2021-10-09 14:10:42 +08:00
|
|
|
|
2022-04-24 11:18:33 +08:00
|
|
|
MMDeploy now supports ncnn version == 1.0.20220216
|
2022-01-07 11:04:28 +08:00
|
|
|
|
2022-06-07 18:05:51 +08:00
|
|
|
## Installation
|
2021-10-12 14:24:33 +08:00
|
|
|
|
2022-06-07 18:05:51 +08:00
|
|
|
### Install ncnn
|
2021-10-12 14:24:33 +08:00
|
|
|
|
|
|
|
- Download VulkanTools for the compilation of ncnn.
|
2021-12-23 13:23:39 +08:00
|
|
|
|
2022-06-17 09:19:10 +08:00
|
|
|
```bash
|
|
|
|
wget https://sdk.lunarg.com/sdk/download/1.2.176.1/linux/vulkansdk-linux-x86_64-1.2.176.1.tar.gz?Human=true -O vulkansdk-linux-x86_64-1.2.176.1.tar.gz
|
|
|
|
tar -xf vulkansdk-linux-x86_64-1.2.176.1.tar.gz
|
|
|
|
export VULKAN_SDK=$(pwd)/1.2.176.1/x86_64
|
|
|
|
export LD_LIBRARY_PATH=$VULKAN_SDK/lib:$LD_LIBRARY_PATH
|
|
|
|
```
|
2021-12-23 13:23:39 +08:00
|
|
|
|
2021-10-12 14:24:33 +08:00
|
|
|
- Check your gcc version.
|
2022-06-17 09:19:10 +08:00
|
|
|
You should ensure your gcc satisfies `gcc >= 6`.
|
2021-12-06 19:03:18 +08:00
|
|
|
|
|
|
|
- Install Protocol Buffers through:
|
2022-06-17 09:19:10 +08:00
|
|
|
|
|
|
|
```bash
|
|
|
|
apt-get install libprotobuf-dev protobuf-compiler
|
|
|
|
```
|
|
|
|
|
|
|
|
- Prepare ncnn Framework
|
|
|
|
|
|
|
|
- Download ncnn source code
|
|
|
|
|
2021-12-06 19:03:18 +08:00
|
|
|
```bash
|
2022-06-17 09:19:10 +08:00
|
|
|
git clone -b 20220216 git@github.com:Tencent/ncnn.git
|
2021-12-06 19:03:18 +08:00
|
|
|
```
|
|
|
|
|
2022-06-17 09:19:10 +08:00
|
|
|
- <font color=red>Make install</font> ncnn library
|
2021-10-12 14:24:33 +08:00
|
|
|
|
2022-06-17 09:19:10 +08:00
|
|
|
```bash
|
|
|
|
cd ncnn
|
|
|
|
export NCNN_DIR=$(pwd)
|
|
|
|
git submodule update --init
|
|
|
|
mkdir -p build && cd build
|
|
|
|
cmake -DNCNN_VULKAN=ON -DNCNN_SYSTEM_GLSLANG=ON -DNCNN_BUILD_EXAMPLES=ON -DNCNN_PYTHON=ON -DNCNN_BUILD_TOOLS=ON -DNCNN_BUILD_BENCHMARK=ON -DNCNN_BUILD_TESTS=ON ..
|
|
|
|
make install
|
|
|
|
```
|
|
|
|
|
|
|
|
- Install pyncnn module
|
|
|
|
|
|
|
|
```bash
|
|
|
|
cd ${NCNN_DIR} # To ncnn root directory
|
|
|
|
cd python
|
|
|
|
pip install -e .
|
|
|
|
```
|
2021-10-12 14:24:33 +08:00
|
|
|
|
2022-06-07 18:05:51 +08:00
|
|
|
### Build custom ops
|
2021-10-12 14:24:33 +08:00
|
|
|
|
|
|
|
Some custom ops are created to support models in OpenMMLab, the custom ops can be built as follows:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
cd ${MMDEPLOY_DIR}
|
2021-12-23 13:23:39 +08:00
|
|
|
mkdir -p build && cd build
|
2021-12-07 10:57:55 +08:00
|
|
|
cmake -DMMDEPLOY_TARGET_BACKENDS=ncnn ..
|
2021-10-12 14:24:33 +08:00
|
|
|
make -j$(nproc)
|
|
|
|
```
|
|
|
|
|
2022-05-09 10:18:10 +08:00
|
|
|
If you haven't installed ncnn in the default path, please add `-Dncnn_DIR` flag in cmake.
|
2021-10-12 14:24:33 +08:00
|
|
|
|
|
|
|
```bash
|
2021-12-23 13:23:39 +08:00
|
|
|
cmake -DMMDEPLOY_TARGET_BACKENDS=ncnn -Dncnn_DIR=${NCNN_DIR}/build/install/lib/cmake/ncnn ..
|
2021-10-12 14:24:33 +08:00
|
|
|
make -j$(nproc)
|
|
|
|
```
|
|
|
|
|
2022-06-07 18:05:51 +08:00
|
|
|
## Convert model
|
2021-10-19 20:30:40 +08:00
|
|
|
|
2022-06-07 18:05:51 +08:00
|
|
|
- This follows the tutorial on [How to convert model](../02-how-to-run/convert_model.md).
|
2021-10-12 14:24:33 +08:00
|
|
|
- The converted model has two files: `.param` and `.bin`, as model structure file and weight file respectively.
|
|
|
|
|
2022-06-07 18:05:51 +08:00
|
|
|
## Reminder
|
2021-12-24 14:27:03 +08:00
|
|
|
|
2022-04-24 11:18:33 +08:00
|
|
|
- In ncnn version >= 1.0.20220216, the dimension of ncnn.Mat should be no more than 4.
|
2021-12-22 15:50:11 +08:00
|
|
|
|
2022-06-07 18:05:51 +08:00
|
|
|
## FAQs
|
2021-10-19 20:30:40 +08:00
|
|
|
|
2021-10-12 14:24:33 +08:00
|
|
|
1. When running ncnn models for inference with custom ops, it fails and shows the error message like:
|
|
|
|
|
2022-06-17 09:19:10 +08:00
|
|
|
```bash
|
|
|
|
TypeError: register mm custom layers(): incompatible function arguments. The following argument types are supported:
|
|
|
|
1.(ar0: ncnn:Net) -> int
|
2021-10-12 14:24:33 +08:00
|
|
|
|
2022-06-17 09:19:10 +08:00
|
|
|
Invoked with: <ncnn.ncnn.Net object at 0x7f7fc4038bb0>
|
|
|
|
```
|
2021-10-19 20:30:40 +08:00
|
|
|
|
2022-06-17 09:19:10 +08:00
|
|
|
This is because of the failure to bind ncnn C++ library to pyncnn. You should build pyncnn from C++ ncnn source code, but not by `pip install`
|