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.

faq.md 20 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  1. # 如何加入技术交流QQ群?
  2. - 打开QQ→点击群聊搜索→搜索群号637093648→输入问题答案:卷卷卷卷卷→进入群聊→准备接受图灵测试(bushi)
  3. - 前往QQ搜索Pocky群:677104663(超多大佬),问题答案:multi level intermediate representation
  4. # 如何看作者b站直播?
  5. - nihui的bilibili直播间:[水竹院落](https://live.bilibili.com/1264617)
  6. # 编译
  7. - ## 怎样下载完整源码?
  8. git clone --recursive https://github.com/Tencent/ncnn/
  9. 或者
  10. 下载 [ncnn-xxxxx-full-source.zip](https://github.com/Tencent/ncnn/releases)
  11. - ## 怎么交叉编译?cmake 工具链怎么设置啊?
  12. 参见 https://github.com/Tencent/ncnn/wiki/how-to-build
  13. - ## The submodules were not downloaded! Please update submodules with "git submodule update --init" and try again
  14. 如上,下载完整源码。或者按提示执行: git submodule update --init
  15. - ## Could NOT find Protobuf (missing: Protobuf_INCLUDE_DIR)
  16. sudo apt-get install libprotobuf-dev protobuf-compiler
  17. - ## Could NOT find CUDA (missing: CUDA_TOOLKIT_ROOT_DIR CUDA_INCLUDE_DIRS CUDA_CUDART_LIBRARY)
  18. https://github.com/Tencent/ncnn/issues/1873
  19. - ## Could not find a package configuration file provided by "OpenCV" with any of the following names: OpenCVConfig.cmake opencv-config.cmake
  20. sudo apt-get install libopencv-dev
  21. 或者自行编译安装,set(OpenCV_DIR {OpenCVConfig.cmake所在目录})
  22. - ## Could not find a package configuration file provided by "ncnn" with any of the following names: ncnnConfig.cmake ncnn-config.cmake
  23. set(ncnn_DIR {ncnnConfig.cmake所在目录})
  24. - ## 找不到 Vulkan,
  25. cmake版本 3.10,否则没有带 FindVulkan.cmake
  26. android-api >= 24
  27. macos 要先执行安装脚本
  28. - ## 如何安装 vulkan sdk
  29. - ## 找不到库(需要根据系统/编译器指定)
  30. undefined reference to __kmpc_for_static_init_4 __kmpc_for_static_fini __kmpc_fork_call ...
  31. 需要链接openmp库
  32. undefined reference to vkEnumerateInstanceExtensionProperties vkGetInstanceProcAddr vkQueueSubmit ...
  33. 需要 vulkan-1.lib
  34. undefined reference to glslang::InitializeProcess() glslang::TShader::TShader(EShLanguage) ...
  35. 需要 glslang.lib OGLCompiler.lib SPIRV.lib OSDependent.lib
  36. undefined reference to AAssetManager_fromJava AAssetManager_open AAsset_seek ...
  37. find_library和target_like_libraries中增加 android
  38. find_package(ncnn)
  39. - ## undefined reference to typeinfo for ncnn::Layer
  40. opencv rtti -> opencv-mobile
  41. - ## undefined reference to __cpu_model
  42. 升级编译器 / libgcc_s libgcc
  43. - ## unrecognized command line option "-mavx2"
  44. 升级 gcc
  45. - ## 为啥自己编译的ncnn android库特别大?
  46. https://github.com/Tencent/ncnn/wiki/build-for-android.zh 以及见 如何裁剪更小的 ncnn 库
  47. - ## ncnnoptimize和自定义层
  48. 先ncnnoptimize再增加自定义层,避免ncnnoptimize不能处理自定义层保存。
  49. - ## rtti/exceptions冲突
  50. 产生原因是项目工程中使用的库配置不一样导致冲突,根据自己的实际情况分析是需要开启还是关闭。ncnn默认是ON,在重新编译ncnn时增加以下2个参数即可:
  51. - 开启:-DNCNN_DISABLE_RTTI=OFF -DNCNN_DISABLE_EXCEPTION=OFF
  52. - 关闭:-DNCNN_DISABLE_RTTI=ON -DNCNN_DISABLE_EXCEPTION=ON
  53. - ## error: undefined symbol: ncnn::Extractor::extract(char const*, ncnn::Mat&)
  54. 可能的情况:
  55. - 尝试升级 Android Studio 的 NDK 版本
  56. # 怎样添加ncnn库到项目中?cmake方式怎么用?
  57. 编译ncnn,make install。linux/windows set/export ncnn_DIR 指向 install目录下包含ncnnConfig.cmake 的目录
  58. - ## android
  59. - ## ios
  60. - ## linux
  61. - ## windows
  62. - ## macos
  63. - ## arm linux
  64. # 转模型问题
  65. - ## caffe
  66. `./caffe2ncnn caffe.prototxt caffe.caffemodel ncnn.param ncnn.bin`
  67. - ## mxnet
  68. ` ./mxnet2ncnn mxnet-symbol.json mxnet.params ncnn.param ncnn.bin`
  69. - ## darknet
  70. [https://github.com/xiangweizeng/darknet2ncnn](https://github.com/xiangweizeng/darknet2ncnn)
  71. - ## pytorch - onnx
  72. [use ncnn with pytorch or onnx](https://github.com/Tencent/ncnn/wiki/use-ncnn-with-pytorch-or-onnx)
  73. - ## tensorflow 1.x/2.x - keras
  74. [https://github.com/MarsTechHAN/keras2ncnn](https://github.com/MarsTechHAN/keras2ncnn) **[@MarsTechHAN](https://github.com/MarsTechHAN)**
  75. - ## tensorflow 2.x - mlir
  76. [通过MLIR将tensorflow2模型转换到ncnn](https://zhuanlan.zhihu.com/p/152535430) **@[nihui](https://www.zhihu.com/people/nihui-2)**
  77. - ## Shape not supported yet! Gather not supported yet! Cast not supported yet!
  78. onnx-simplifier 静态shape
  79. - ## convertmodel
  80. [https://convertmodel.com/](https://convertmodel.com/) **[@大老师](https://github.com/daquexian)**
  81. - ## netron
  82. [https://github.com/lutzroeder/netron](https://github.com/lutzroeder/netron)
  83. - ## 怎么生成有固定 shape 信息的模型?
  84. Input 0=w 1=h 2=c
  85. - ## why gpu能更快
  86. - ## ncnnoptimize 怎么转成 fp16 模型
  87. `ncnnoptimize model.param model.bin yolov5s-opt.param yolov5s-opt.bin 65536`
  88. - ## ncnnoptimize 怎样查看模型的 FLOPS / 内存占用情况
  89. - ## 怎么修改模型支持动态 shape?
  90. Interp Reshape
  91. - ## 如何将模型转换为代码内嵌到程序里?
  92. ncnn2mem
  93. - ## 如何加密模型?
  94. https://zhuanlan.zhihu.com/p/268327784
  95. - ## Linux下转的ncnn模型,Windows/MacOS/Android/.. 也能直接用吗?
  96. Yes,全平台通用
  97. - ## 如何去掉后处理,再导出 onnx?
  98. 检测:
  99. 参考up的一篇文章<https://zhuanlan.zhihu.com/p/128974102>,步骤三就是去掉后处理,再导出onnx,其中去掉后处理可以是项目内测试时去掉后续步骤的结果。
  100. - ## pytorch 有的层导不出 onnx 怎么办?
  101. 方式一:
  102. ONNX_ATEN_FALLBACK
  103. 完全自定义的op,先改成能导出的(如 concat slice),转到 ncnn 后再修改 param
  104. 方式二:
  105. 可以使用PNNX来试试,参考以下文章大概说明:
  106. 1. [Windows/Linux/macOS 编译 PNNX 步骤](https://zhuanlan.zhihu.com/p/431833958)
  107. 2. [5分钟学会!用 PNNX 转换 TorchScript 模型到 ncnn 模型](https://zhuanlan.zhihu.com/p/427512763)
  108. # 使用
  109. - ## vkEnumeratePhysicalDevices failed -3
  110. - ## vkCreateInstance failed -9
  111. 出现此类问题请先更新GPU驱动。Please upgrade your GPU driver if you encounter this crash or error.
  112. 这里提供了一些品牌的GPU驱动下载网址.We have provided some drivers' download pages here.
  113. [Intel](https://downloadcenter.intel.com/product/80939/Graphics-Drivers),[AMD](https://www.amd.com/en/support),[Nvidia](https://www.nvidia.com/Download/index.aspx)
  114. - ## ModuleNotFoundError: No module named 'ncnn.ncnn'
  115. python setup.py develop
  116. - ## fopen nanodet-m.param failed
  117. 文件路径 working dir
  118. File not found or not readable. Make sure that XYZ.param/XYZ.bin is accessible.
  119. - ## find_blob_index_by_name data / output / ... failed
  120. layer name vs blob name
  121. param.bin 应该用 xxx.id.h 的枚举
  122. - ## parse magic failed
  123. - ## param is too old, please regenerate
  124. 模型本身有问题
  125. Your model file is being the old format converted by an old caffe2ncnn tool.
  126. Checkout the latest ncnn code, build it and regenerate param and model binary files, and that should work.
  127. Make sure that your param file starts with the magic number 7767517.
  128. you may find more info on use-ncnn-with-alexnet
  129. When adding the softmax layer yourself, you need to add 1=1
  130. - ## set_vulkan_compute failed, network use_vulkan_compute disabled
  131. 你应该在 load_param / load_model 之前设置 net.opt.use_vulkan_compute = true;
  132. - ## 多个blob输入,多个blob输出,怎么做?
  133. 多次执行`ex.input()` 和 `ex.extract()`
  134. ```
  135. ex.input("data1", in_1);
  136. ex.input("data2", in_2);
  137. ex.extract("output1", out_1);
  138. ex.extract("output2", out_2);
  139. ```
  140. - ## Extractor extract 多次会重复计算吗?
  141. 不会
  142. - ## 如何看每一层的耗时?
  143. cmake -DNCNN_BENCHMARK=ON ..
  144. - ## 如何转换 cv::Mat CV_8UC3 BGR 图片
  145. from_pixels to_pixels
  146. - ## 如何转换 float 数据为 ncnn::Mat
  147. 首先,自己申请的内存需要自己管理,此时ncnn::Mat不会自动给你释放你传过来的float数据
  148. ``` c++
  149. std::vector<float> testData(60, 1.0); // 利用std::vector<float>自己管理内存的申请和释放
  150. ncnn::Mat in1(60, (void*)testData.data()).reshape(4, 5, 3); // 把float数据的指针转成void*传过去即可,甚至还可以指定维度(up说最好使用reshape用来解决channel gap)
  151. float* a = new float[60]; // 自己new一块内存,后续需要自己释放
  152. ncnn::Mat in2 = ncnn::Mat(60, (void*)a).reshape(4, 5, 3).clone(); // 使用方法和上面相同,clone() to transfer data owner
  153. ```
  154. - ## 如何初始化 ncnn::Mat 为全 0
  155. `mat.fill(0.f);`
  156. - ## 如何查看/获取版本号
  157. cmake时会打印
  158. c_api.h ncnn_version()
  159. 自己拼 1.0+yyyymmdd
  160. - ## 如何转换 yuv 数据
  161. yuv420sp2rgb yuv420sp2rgb_nv12
  162. **[@metarutaiga](https://github.com/metarutaiga/xxYUV)**
  163. - ## 如何 resize crop rotate 图片
  164. [efficient roi resize rotate](https://github.com/Tencent/ncnn/wiki/efficient-roi-resize-rotate)
  165. - ## 如何人脸5点对齐
  166. get_affine_transform
  167. warpaffine_bilinear_c3
  168. ```c
  169. // 计算变换矩阵 并且求逆变换
  170. int type = 0; // 0->区域外填充为v[0],v[1],v[2], -233->区域外不处理
  171. unsigned int v = 0;
  172. float tm[6];
  173. float tm_inv[6];
  174. // 人脸区域在原图上的坐标和宽高
  175. float src_x = target->det.rect.x / target->det.w * pIveImageU8C3->u32Width;
  176. float src_y = target->det.rect.y / target->det.h * pIveImageU8C3->u32Height;
  177. float src_w = target->det.rect.w / target->det.w * pIveImageU8C3->u32Width;
  178. float src_h = target->det.rect.h / target->det.h * pIveImageU8C3->u32Height;
  179. float point_src[10] = {
  180. src_x + src_w * target->attr.land[0][0], src_x + src_w * target->attr.land[0][1],
  181. src_x + src_w * target->attr.land[1][0], src_x + src_w * target->attr.land[1][1],
  182. src_x + src_w * target->attr.land[2][0], src_x + src_w * target->attr.land[2][1],
  183. src_x + src_w * target->attr.land[3][0], src_x + src_w * target->attr.land[3][1],
  184. src_x + src_w * target->attr.land[4][0], src_x + src_w * target->attr.land[4][1],
  185. };
  186. float point_dst[10] = { // +8 是因为我们处理112*112的图
  187. 30.2946f + 8.0f, 51.6963f,
  188. 65.5318f + 8.0f, 51.5014f,
  189. 48.0252f + 8.0f, 71.7366f,
  190. 33.5493f + 8.0f, 92.3655f,
  191. 62.7299f + 8.0f, 92.2041f,
  192. };
  193. // 第一种方式:先计算变换在求逆
  194. AffineTrans::get_affine_transform(point_src, point_dst, 5, tm);
  195. AffineTrans::invert_affine_transform(tm, tm_inv);
  196. // 第二种方式:直接拿到求逆的结果
  197. // AffineTrans::get_affine_transform(point_dst, point_src, 5, tm_inv);
  198. // rgb 分离的,所以要单独处理
  199. for(int c = 0; c < 3; c++)
  200. {
  201. unsigned char* pSrc = malloc(xxx);
  202. unsigned char* pDst = malloc(xxx);
  203. ncnn::warpaffine_bilinear_c1(pSrc, SrcWidth, SrcHeight, SrcStride[c], pDst, DstWidth, DstHeight, DstStride[c], tm_inv, type, v);
  204. }
  205. // rgb packed则可以一次处理
  206. ncnn::warpaffine_bilinear_c3(pSrc, SrcWidth, SrcHeight, SrcStride, pDst, DstWidth, DstHeight, DstStride, tm_inv, type, v);
  207. ```
  208. - ## 如何获得中间层的blob输出
  209. ncnn::Mat output;
  210. ex.extract("your_blob_name", output);
  211. - ## 为什么我使用GPU,但是GPU占用为0
  212. windows 10 任务管理器 - 性能选项卡 - GPU - 选择其中一个视图左上角的下拉箭头切换到 Compute_0 / Compute_1 / Cuda
  213. 你还可以安装软件:GPU-Z
  214. - ## layer XYZ not exists or registered
  215. Your network contains some operations that are not implemented in ncnn.
  216. You may implement them as custom layer followed in how-to-implement-custom-layer-step-by-step.
  217. Or you could simply register them as no-op if you are sure those operations make no sense.
  218. ```
  219. class Noop : public ncnn::Layer {};
  220. DEFINE_LAYER_CREATOR(Noop)
  221. net.register_custom_layer("LinearRegressionOutput", Noop_layer_creator);
  222. net.register_custom_layer("MAERegressionOutput", Noop_layer_creator);
  223. ```
  224. - ## network graph not ready
  225. You shall call Net::load_param() first, then Net::load_model().
  226. This error may also happens when Net::load_param() failed, but not properly handled.
  227. For more information about the ncnn model load api, see ncnn-load-model
  228. - ## memory not 32-bit aligned at XYZ
  229. The pointer passed to Net::load_param() or Net::load_model() is not 32bit aligned.
  230. In practice, the head pointer of std::vector is not guaranteed to be 32bit aligned.
  231. you can store your binary buffer in ncnn::Mat structure, its internal memory is aligned.
  232. - ## crash on android with '__kmp_abort_process'
  233. This usually happens if you bundle multiple shared library with openmp linked
  234. It is actually an issue of the android ndk https://github.com/android/ndk/issues/1028
  235. On old android ndk, modify the link flags as
  236. -Wl,-Bstatic -lomp -Wl,-Bdynamic
  237. For recent ndk >= 21
  238. -fstatic-openmp
  239. - ## dlopen failed: library "libomp.so" not found
  240. Newer android ndk defaults to dynamic openmp runtime
  241. modify the link flags as
  242. -fstatic-openmp -fopenmp
  243. - ## crash when freeing a ncnn dynamic library(.dll/.so) built with openMP
  244. for optimal performance, the openmp threadpool spin waits for about a second prior to shutting down in case more work becomes available.
  245. If you unload a dynamic library that's in the process of spin-waiting, it will crash in the manner you see (most of the time).
  246. Just set OMP_WAIT_POLICY=passive in your environment, before calling loadlibrary. or Just wait a few seconds before calling freelibrary.
  247. You can also use the following method to set environment variables in your code:
  248. for msvc++:
  249. SetEnvironmentVariable(_T("OMP_WAIT_POLICY"), _T("passive"));
  250. for g++:
  251. setenv("OMP_WAIT_POLICY", "passive", 1)
  252. reference: https://stackoverflow.com/questions/34439956/vc-crash-when-freeing-a-dll-built-with-openmp
  253. # 跑出来的结果对不上
  254. [ncnn-produce-wrong-result](https://github.com/Tencent/ncnn/wiki/FAQ-ncnn-produce-wrong-result)
  255. - ## 如何打印 ncnn::Mat 的值?
  256. ```C++
  257. void pretty_print(const ncnn::Mat& m)
  258. {
  259. for (int q=0; q<m.c; q++)
  260. {
  261. const float* ptr = m.channel(q);
  262. for (int y=0; y<m.h; y++)
  263. {
  264. for (int x=0; x<m.w; x++)
  265. {
  266. printf("%f ", ptr[x]);
  267. }
  268. ptr += m.w;
  269. printf("\n");
  270. }
  271. printf("------------------------\n");
  272. }
  273. }
  274. ```
  275. In Android Studio, `printf` will not work, you can use `__android_log_print` instead. Example :
  276. ```C++
  277. #include <android/log.h> // Don't forget this
  278. void pretty_print(const ncnn::Mat& m)
  279. {
  280. for (int q=0; q<m.c; q++)
  281. {
  282. for (int y=0; y<m.h; y++)
  283. {
  284. for (int x=0; x<m.w; x++)
  285. {
  286. __android_log_print(ANDROID_LOG_DEBUG,"LOG_TAG","ncnn Mat is : %f", m.channel(q).row(y)[x]);
  287. }
  288. }
  289. }
  290. }
  291. ```
  292. - ## 如何可视化 ncnn::Mat 的值?
  293. ```
  294. void visualize(const char* title, const ncnn::Mat& m)
  295. {
  296. std::vector<cv::Mat> normed_feats(m.c);
  297. for (int i=0; i<m.c; i++)
  298. {
  299. cv::Mat tmp(m.h, m.w, CV_32FC1, (void*)(const float*)m.channel(i));
  300. cv::normalize(tmp, normed_feats[i], 0, 255, cv::NORM_MINMAX, CV_8U);
  301. cv::cvtColor(normed_feats[i], normed_feats[i], cv::COLOR_GRAY2BGR);
  302. // check NaN
  303. for (int y=0; y<m.h; y++)
  304. {
  305. const float* tp = tmp.ptr<float>(y);
  306. uchar* sp = normed_feats[i].ptr<uchar>(y);
  307. for (int x=0; x<m.w; x++)
  308. {
  309. float v = tp[x];
  310. if (v != v)
  311. {
  312. sp[0] = 0;
  313. sp[1] = 0;
  314. sp[2] = 255;
  315. }
  316. sp += 3;
  317. }
  318. }
  319. }
  320. int tw = m.w < 10 ? 32 : m.w < 20 ? 16 : m.w < 40 ? 8 : m.w < 80 ? 4 : m.w < 160 ? 2 : 1;
  321. int th = (m.c - 1) / tw + 1;
  322. cv::Mat show_map(m.h * th, m.w * tw, CV_8UC3);
  323. show_map = cv::Scalar(127);
  324. // tile
  325. for (int i=0; i<m.c; i++)
  326. {
  327. int ty = i / tw;
  328. int tx = i % tw;
  329. normed_feats[i].copyTo(show_map(cv::Rect(tx * m.w, ty * m.h, m.w, m.h)));
  330. }
  331. cv::resize(show_map, show_map, cv::Size(0,0), 2, 2, cv::INTER_NEAREST);
  332. cv::imshow(title, show_map);
  333. }
  334. ```
  335. - ## 总是输出第一张图的结果
  336. 复用 Extractor?!
  337. - ## 启用fp16时的精度有差异
  338. net.opt.use_fp16_packed = false;
  339. net.opt.use_fp16_storage = false;
  340. net.opt.use_fp16_arithmetic = false;
  341. [ncnn-produce-wrong-result](https://github.com/Tencent/ncnn/wiki/FAQ-ncnn-produce-wrong-result)
  342. # 如何跑得更快?内存占用更少?库体积更小?
  343. - ## fp32 fp16
  344. - ## 大小核绑定
  345. ncnn::set_cpu_powersave(int)绑定大核或小核
  346. 注意windows系统不支持绑核。
  347. ncnn支持不同的模型运行在不同的核心。假设硬件平台有2个大核,4个小核,你想把netA运行在大核,netB运行在小核。
  348. 可以通过std::thread or pthread创建两个线程,运行如下代码:
  349. 0:全部
  350. 1:小核
  351. 2:大核
  352. ```
  353. void thread_1()
  354. {
  355. ncnn::set_cpu_powersave(2); // bind to big cores
  356. netA.opt.num_threads = 2;
  357. }
  358. void thread_2()
  359. {
  360. ncnn::set_cpu_powersave(1); // bind to little cores
  361. netB.opt.num_threads = 4;
  362. }
  363. ```
  364. [openmp-best-practice.zh.md](https://github.com/Tencent/ncnn/blob/master/docs/how-to-use-and-FAQ/openmp-best-practice.zh.md)
  365. - ## 查看 CPU 或 GPU 数量
  366. get_cpu_count
  367. get_gpu_count
  368. - ## ncnnoptimize
  369. 使用方式一:
  370. - ./ncnnoptimize ncnn.param ncnn.bin new.param new.bin flag
  371. <br/>注意这里的flag指的是fp32和fp16,其中0指的是fp32,1指的是fp16
  372. 使用方式二:
  373. - ./ncnnoptimize ncnn.param ncnn.bin new.param new.bin flag cutstartname cutendname
  374. <br/>cutstartname:模型截取的起点
  375. <br/>cutendname:模型截取的终点
  376. - ## 如何使用量化工具?
  377. [Post Training Quantization Tools](https://github.com/Tencent/ncnn/tree/master/tools/quantize)
  378. - ## 如何设置线程数?
  379. opt.num_threads
  380. - ## 如何降低CPU占用率?
  381. net.opt.openmp_blocktime = 0;
  382. OMP_WAIT_POLICY=passive
  383. - ## 如何 batch inference?
  384. ```
  385. int max_batch_size = vkdev->info.compute_queue_count;
  386. ncnn::Mat inputs[1000];
  387. ncnn::Mat outputs[1000];
  388. #pragma omp parallel for num_threads(max_batch_size)
  389. for (int i=0; i<1000; i++)
  390. {
  391. ncnn::Extractor ex = net1.create_extractor();
  392. ex.input("data", inputs[i]);
  393. ex.extract("prob", outputs[i]);
  394. }
  395. ```
  396. - ## partial graph inference
  397. 先 extract 分类,判断后,再 extract bbox
  398. - ## 如何启用 bf16s 加速?
  399. ```
  400. net.opt.use_packing_layout = true;
  401. net.opt.use_bf16_storage = true;
  402. ```
  403. [用bf16加速ncnn](https://zhuanlan.zhihu.com/p/112564372) **@[nihui](https://www.zhihu.com/people/nihui-2)**
  404. A53
  405. - ## 如何裁剪更小的 ncnn 库?
  406. [build-minimal-library](https://github.com/Tencent/ncnn/wiki/build-minimal-library)
  407. - ## net.opt sgemm winograd fp16_storage 各是有什么作用?
  408. 对内存消耗的影响
  409. # 白嫖项目
  410. - ## nanodet
  411. # 其他
  412. - ## up主用的什么系统/编辑器/开发环境?
  413. | 软件类型 | 软件名称 |
  414. | ------------| ----------- |
  415. | 系统 | Fedora |
  416. | 桌面环境 | KDE |
  417. | 编辑器 | Kate |
  418. | 画草图 | kolourpaint |
  419. | 画函数图像 | kmplot |
  420. | bilibili直播 | OBS |