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.

Home.md 2.6 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. ### input data and extract output
  2. ```
  3. #include <opencv2/core/core.hpp>
  4. #include <opencv2/highgui/highgui.hpp>
  5. #include "net.h"
  6. int main()
  7. {
  8. cv::Mat img = cv::imread("image.ppm", CV_LOAD_IMAGE_GRAYSCALE);
  9. int w = img.cols;
  10. int h = img.rows;
  11. // subtract 128, norm to -1 ~ 1
  12. ncnn::Mat in = ncnn::Mat::from_pixels_resize(img.data, ncnn::Mat::PIXEL_GRAY, w, h, 60, 60);
  13. float mean[1] = { 128.f };
  14. float norm[1] = { 1/128.f };
  15. in.substract_mean_normalize(mean, norm);
  16. ncnn::Net net;
  17. net.load_param("model.param");
  18. net.load_model("model.bin");
  19. ncnn::Extractor ex = net.create_extractor();
  20. ex.set_light_mode(true);
  21. ex.set_num_threads(4);
  22. ex.input("data", in);
  23. ncnn::Mat feat;
  24. ex.extract("output", feat);
  25. return 0;
  26. }
  27. ```
  28. ### print Mat content
  29. ```
  30. void pretty_print(const Mat& m)
  31. {
  32. for (int q=0; q<m.c; q++)
  33. {
  34. const float* ptr = m.channel(q);
  35. for (int y=0; y<m.h; y++)
  36. {
  37. for (int x=0; x<m.w; x++)
  38. {
  39. printf("%f ", ptr[x]);
  40. }
  41. ptr += m.w;
  42. printf("\n");
  43. }
  44. printf("------------------------\n");
  45. }
  46. }
  47. ```
  48. ### caffe-android-lib+openblas vs ncnn
  49. use squeezenet v1.1, nexus6p, android 7.1.2
  50. memory usage is the RSS item in top utility output
  51. |compare item|caffe-android-lib+openblas|ncnn|
  52. |---|---|---|
  53. |inference time(1 thread)|228ms|88ms|
  54. |inference time(8 thread)|152ms|38ms|
  55. |memory usage|138.16M|21.56M|
  56. |library binary size|6.9M|<500K|
  57. |compability|armeabi-v7a-hard with neon or arm64-v8a|armeabi-v7a with neon or arm64-v8a|
  58. |thirdparty dependency|boost gflags glog lmdb openblas opencv protobuf|none|
  59. ### FAQ
  60. Q ncnn的起源
  61. A 深度学习算法要在手机上落地,caffe依赖太多,手机上也没有cuda,需要个又快又小的前向网络实现
  62. Q ncnn名字的来历
  63. A cnn就是卷积神经网络的缩写,开头的n算是一语n关。比如new/next(全新的实现),naive(ncnn是naive实现),neon(ncnn最初为手机优化),up主名字(←_←)
  64. Q 支持哪些平台
  65. A 跨平台,主要支持 android,次要支持 ios / linux / windows
  66. Q 计算精度如何
  67. A armv7 neon float 不遵照 ieee754 标准,有些采用快速实现(如exp sin等),速度快但确保精度足够高
  68. Q pc 上的速度很慢
  69. A pc都是x86架构的,基本没做什么优化,主要用来核对结果,毕竟up主精力是有限的(
  70. Q 为何没有 logo
  71. A up主是mc玩家,所以开始是找了萌萌的苦力怕当看板娘的,但是这样子会侵权对吧,只好空出来了...