You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 3.2 kB

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