当前位置:   article > 正文

ncnn DataReader&Extractor&blob_ncnn extrator

ncnn extrator

ncnn-blob.h

网络中输入-输出对应标记(网络层中的节点名??)。

  1. class NCNN_EXPORT Blob
  2. {
  3. public:
  4. // empty
  5. Blob();
  6. public:
  7. #if NCNN_STRING
  8. // blob name
  9. std::string name;
  10. #endif // NCNN_STRING
  11. // layer index which produce this blob as output
  12. int producer;
  13. // layer index which need this blob as input
  14. int consumer;
  15. // shape hint
  16. Mat shape;
  17. };

cpp

  1. Blob::Blob()
  2. {
  3. producer = -1;
  4. consumer = -1;
  5. }

ncnn-datareader.h

文件读取

  1. // data read wrapper
  2. class NCNN_EXPORT DataReader
  3. {
  4. public:
  5. DataReader();
  6. virtual ~DataReader();
  7. #if NCNN_STRING
  8. // parse plain param text
  9. // return 1 if scan success
  10. //解析模型文件 ,成功返回1
  11. virtual int scan(const char* format, void* p) const;
  12. #endif // NCNN_STRING
  13. // read binary param and model data
  14. // return bytes read
  15. //读取二进制模型数据 返回字节数
  16. virtual size_t read(void* buf, size_t size) const;
  17. // get model data reference
  18. // return bytes referenced
  19. virtual size_t reference(size_t size, const void** buf) const;
  20. };

ncnn-net.h

提取

  1. class ExtractorPrivate;
  2. class NCNN_EXPORT Extractor
  3. {
  4. public:
  5. virtual ~Extractor();
  6. // copy
  7. Extractor(const Extractor&);
  8. // assign
  9. Extractor& operator=(const Extractor&);
  10. // clear blob mats and alloctors
  11. void clear();
  12. // enable light mode
  13. // intermediate blob will be recycled when enabled
  14. // enabled by default
  15. void set_light_mode(bool enable);
  16. // set thread count for this extractor
  17. // this will overwrite the global setting
  18. // default count is system depended
  19. void set_num_threads(int num_threads);
  20. // set blob memory allocator
  21. void set_blob_allocator(Allocator* allocator);
  22. // set workspace memory allocator
  23. void set_workspace_allocator(Allocator* allocator);
  24. #if NCNN_VULKAN
  25. void set_vulkan_compute(bool enable);
  26. void set_blob_vkallocator(VkAllocator* allocator);
  27. void set_workspace_vkallocator(VkAllocator* allocator);
  28. void set_staging_vkallocator(VkAllocator* allocator);
  29. #endif // NCNN_VULKAN
  30. #if NCNN_STRING
  31. // set input by blob name
  32. // return 0 if success
  33. int input(const char* blob_name, const Mat& in);
  34. // get result by blob name
  35. // return 0 if success
  36. // type = 0, default
  37. // type = 1, do not convert fp16/bf16 or / and packing
  38. int extract(const char* blob_name, Mat& feat, int type = 0);
  39. #endif // NCNN_STRING
  40. // set input by blob index
  41. // return 0 if success
  42. int input(int blob_index, const Mat& in);
  43. // get result by blob index
  44. // return 0 if success
  45. // type = 0, default
  46. // type = 1, do not convert fp16/bf16 or / and packing
  47. int extract(int blob_index, Mat& feat, int type = 0);
  48. #if NCNN_VULKAN
  49. #if NCNN_STRING
  50. // set input by blob name
  51. // return 0 if success
  52. int input(const char* blob_name, const VkMat& in);
  53. // get result by blob name
  54. // return 0 if success
  55. int extract(const char* blob_name, VkMat& feat, VkCompute& cmd);
  56. // set input by blob name
  57. // return 0 if success
  58. int input(const char* blob_name, const VkImageMat& in);
  59. // get result by blob name
  60. // return 0 if success
  61. int extract(const char* blob_name, VkImageMat& feat, VkCompute& cmd);
  62. #endif // NCNN_STRING
  63. // set input by blob index
  64. // return 0 if success
  65. int input(int blob_index, const VkMat& in);
  66. // get result by blob index
  67. // return 0 if success
  68. int extract(int blob_index, VkMat& feat, VkCompute& cmd);
  69. // set input by blob index
  70. // return 0 if success
  71. int input(int blob_index, const VkImageMat& in);
  72. // get result by blob index
  73. // return 0 if success
  74. int extract(int blob_index, VkImageMat& feat, VkCompute& cmd);
  75. #endif // NCNN_VULKAN
  76. protected:
  77. friend Extractor Net::create_extractor() const;
  78. Extractor(const Net* net, size_t blob_count);
  79. private:
  80. ExtractorPrivate* const d;
  81. };

  1. //通过输入名获得对应的输入索引
  2. int Extractor::input(const char* blob_name, const VkImageMat& in)
  3. {
  4. int blob_index = d->net->find_blob_index_by_name(blob_name);
  5. if (blob_index == -1)
  6. {
  7. NCNN_LOGE("Try");
  8. const std::vector<const char*>& input_names = d->net->input_names();
  9. for (size_t i = 0; i < input_names.size(); i++)
  10. {
  11. NCNN_LOGE(" ex.input(\"%s\", in%d);", input_names[i], (int)i);
  12. }
  13. return -1;
  14. }
  15. return input(blob_index, in);
  16. }
  17. //通过输入索引获得结果值
  18. int Extractor::input(int blob_index, const Mat& in)
  19. {
  20. if (blob_index < 0 || blob_index >= (int)d->blob_mats.size())
  21. return -1;
  22. d->blob_mats[blob_index] = in;
  23. return 0;
  24. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/703306
推荐阅读
相关标签
  

闽ICP备14008679号