当前位置:网站首页>ncnn DataReader&Extractor&blob
ncnn DataReader&Extractor&blob
2022-07-17 00:17:00 【HySmiley】
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;
}
边栏推荐
- RHCE8学习指南第2章 基本命令的使用
- 微信小程序--Taro框架实际开发中的问题汇总
- Regular and extended expressions, sed text processor and awk tool, changing IP address with script
- Rhce8 Study Guide Chapter 6 archiving and compression
- MySQL master-slave replication + read write separation
- 三层交换机配置VLAN和使用OSPF协议
- A practical case of redisson's implementation of distributed locks - lock single key - lock multiple keys - watchdog
- Oracle获取最后一条,第一条数据(按时间获取第一条和最后一条数据)
- Image quality evaluation indicators: SNR, PSNR, MSE and SSIM
- 全虚拟化与半虚拟化
猜你喜欢
【NoSQL】redis高可用和持久化
[redis] what is progressive rehash
RHCE ansible second operation
PXE automated installation
Brief introduction of Feature Engineering and its implementation of sklearn
What happens when you get stuck compiling and installing MySQL database in Linux system?
SSH Remote Control and access
HCIA static comprehensive experiment
ELK日志分析系统
An example of C language callback function & sprinf practical application
随机推荐
微信小程序
Circular statements and functions of shell scripts
RHCE8学习指南第一章 安装RHEL8.4
Detailed explanation of dynamic compression and static compression of gzip
RHCE Study Guide Chapter 5 VIM editor
Binary installation kubernetes 1.23.2
Rhce8 Study Guide Chapter 7 service management
1. Introduction, analysis and implementation of asynctool framework
一文搞懂JVM内存结构
Mysql优化之索引
Rsync remote synchronization (incremental backup)
Shell script variables, script writing and execution (deploy Apache and remote backup MySQL database)
Flyway's SaaS multi tenant implementation scheme
MySQL master-slave replication + read write separation
FTP服务
ENSP静态路由实验
多层数据包结构及TCP三次握手
DHCP principle and configuration
备份kubernetes 备份etcd数据
Dynamic programming - 01 knapsack problem