ncnn-blob.h
网络中输入-输出对应标记(网络层中的节点名??)。
class NCNN_EXPORT Blob
{
public:
// empty
Blob();
public:
#if NCNN_STRING
// blob name
std::string name;
#endif // NCNN_STRING
// layer index which produce this blob as output
int producer;
// layer index which need this blob as input
int consumer;
// shape hint
Mat shape;
};
cpp
Blob::Blob()
{
producer = -1;
consumer = -1;
}
ncnn-datareader.h
文件读取
// data read wrapper
class NCNN_EXPORT DataReader
{
public:
DataReader();
virtual ~DataReader();
#if NCNN_STRING
// parse plain param text
// return 1 if scan success
//解析模型文件 ,成功返回1
virtual int scan(const char* format, void* p) const;
#endif // NCNN_STRING
// read binary param and model data
// return bytes read
//读取二进制模型数据 返回字节数
virtual size_t read(void* buf, size_t size) const;
// get model data reference
// return bytes referenced
virtual size_t reference(size_t size, const void** buf) const;
};
ncnn-net.h
提取
class ExtractorPrivate;
class NCNN_EXPORT Extractor
{
public:
virtual ~Extractor();
// copy
Extractor(const Extractor&);
// assign
Extractor& operator=(const Extractor&);
// clear blob mats and alloctors
void clear();
// enable light mode
// intermediate blob will be recycled when enabled
// enabled by default
void set_light_mode(bool enable);
// set thread count for this extractor
// this will overwrite the global setting
// default count is system depended
void set_num_threads(int num_threads);
// set blob memory allocator
void set_blob_allocator(Allocator* allocator);
// set workspace memory allocator
void set_workspace_allocator(Allocator* allocator);
#if NCNN_VULKAN
void set_vulkan_compute(bool enable);
void set_blob_vkallocator(VkAllocator* allocator);
void set_workspace_vkallocator(VkAllocator* allocator);
void set_staging_vkallocator(VkAllocator* allocator);
#endif // NCNN_VULKAN
#if NCNN_STRING
// set input by blob name
// return 0 if success
int input(const char* blob_name, const Mat& in);
// get result by blob name
// return 0 if success
// type = 0, default
// type = 1, do not convert fp16/bf16 or / and packing
int extract(const char* blob_name, Mat& feat, int type = 0);
#endif // NCNN_STRING
// set input by blob index
// return 0 if success
int input(int blob_index, const Mat& in);
// get result by blob index
// return 0 if success
// type = 0, default
// type = 1, do not convert fp16/bf16 or / and packing
int extract(int blob_index, Mat& feat, int type = 0);
#if NCNN_VULKAN
#if NCNN_STRING
// set input by blob name
// return 0 if success
int input(const char* blob_name, const VkMat& in);
// get result by blob name
// return 0 if success
int extract(const char* blob_name, VkMat& feat, VkCompute& cmd);
// set input by blob name
// return 0 if success
int input(const char* blob_name, const VkImageMat& in);
// get result by blob name
// return 0 if success
int extract(const char* blob_name, VkImageMat& feat, VkCompute& cmd);
#endif // NCNN_STRING
// set input by blob index
// return 0 if success
int input(int blob_index, const VkMat& in);
// get result by blob index
// return 0 if success
int extract(int blob_index, VkMat& feat, VkCompute& cmd);
// set input by blob index
// return 0 if success
int input(int blob_index, const VkImageMat& in);
// get result by blob index
// return 0 if success
int extract(int blob_index, VkImageMat& feat, VkCompute& cmd);
#endif // NCNN_VULKAN
protected:
friend Extractor Net::create_extractor() const;
Extractor(const Net* net, size_t blob_count);
private:
ExtractorPrivate* const d;
};
//通过输入名获得对应的输入索引
int Extractor::input(const char* blob_name, const VkImageMat& in)
{
int blob_index = d->net->find_blob_index_by_name(blob_name);
if (blob_index == -1)
{
NCNN_LOGE("Try");
const std::vector<const char*>& input_names = d->net->input_names();
for (size_t i = 0; i < input_names.size(); i++)
{
NCNN_LOGE(" ex.input(\"%s\", in%d);", input_names[i], (int)i);
}
return -1;
}
return input(blob_index, in);
}
//通过输入索引获得结果值
int Extractor::input(int blob_index, const Mat& in)
{
if (blob_index < 0 || blob_index >= (int)d->blob_mats.size())
return -1;
d->blob_mats[blob_index] = in;
return 0;
}