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.0 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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 enable the usage of vulkan, you can install as following:
  33. ```
  34. python setup.py install --vulkan=on
  35. ```
  36. > **Attention:**
  37. >
  38. > To enable Vulkan support, you must first install the Vulkan SDK.
  39. >
  40. > **For Windows or Linux Users:**
  41. >
  42. > Ensure that the `VULKAN_SDK` environment variable is set to the path of the Vulkan SDK.
  43. >
  44. > **For MacOS Users:**
  45. >
  46. > 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).
  47. ## Custom-build & Install
  48. 1. clone ncnn and init submodule.
  49. ```bash
  50. cd /pathto/ncnn
  51. git submodule init && git submodule update
  52. ```
  53. 2. build.
  54. ```bash
  55. mkdir build
  56. cd build
  57. cmake -DNCNN_PYTHON=ON ..
  58. make
  59. ```
  60. 3. install
  61. ```bash
  62. cd /pathto/ncnn
  63. pip install .
  64. ```
  65. if you use conda or miniconda, you can also install as following:
  66. ```bash
  67. cd /pathto/ncnn
  68. python3 setup.py install
  69. ```
  70. ## Tests
  71. **test**
  72. ```bash
  73. cd /pathto/ncnn/python
  74. python3 tests/test.py
  75. ```
  76. **benchmark**
  77. ```bash
  78. cd /pathto/ncnn/python
  79. python3 tests/benchmark.py
  80. ```
  81. ## Numpy
  82. **ncnn.Mat->numpy.array, with no memory copy**
  83. ```bash
  84. mat = ncnn.Mat(...)
  85. mat_np = np.array(mat)
  86. ```
  87. **numpy.array->ncnn.Mat, with no memory copy**
  88. ```bash
  89. mat_np = np.array(...)
  90. mat = ncnn.Mat(mat_np)
  91. ```
  92. # Model Zoo
  93. install requirements
  94. ```bash
  95. pip install -r requirements.txt
  96. ```
  97. then you can import ncnn.model_zoo and get model list as follow:
  98. ```bash
  99. import ncnn
  100. import ncnn.model_zoo as model_zoo
  101. print(model_zoo.get_model_list())
  102. ```
  103. models now in model zoo are as list below:
  104. ```bash
  105. mobilenet_yolov2
  106. mobilenetv2_yolov3
  107. yolov4_tiny
  108. yolov4
  109. yolov5s
  110. yolact
  111. mobilenet_ssd
  112. squeezenet_ssd
  113. mobilenetv2_ssdlite
  114. mobilenetv3_ssdlite
  115. squeezenet
  116. faster_rcnn
  117. peleenet_ssd
  118. retinaface
  119. rfcn
  120. shufflenetv2
  121. simplepose
  122. nanodet
  123. ```
  124. all model in model zoo has example in ncnn/python/examples folder
  125. # Custom Layer
  126. custom layer demo is in ncnn/python/ncnn/model_zoo/yolov5.py:23