赞
踩
ncnn中做了三层封装,分别是layer,net,extractor。extractor是最后一道封装,也是实现前向推理流程的部件。
ex.input("data", in); // 传入图像数据
int Extractor::input(const char* blob_name, const Mat& in)
{
int blob_index = net->find_blob_index_by_name(blob_name);
if (blob_index == -1)
return -1;
blob_mats[blob_index] = in;
return 0;
}
将图像数据放入extracor的blob_mats中
ret = net->forward_layer(layer_index, blob_mats, lightmode); // 递归调用,将模型的所有输出存入blob_mats
ncnn在这里应用了递归调用,按顺序计算网络的输出,并保存在blob_mats中
Mat bottom_blob = blob_mats[bottom_blob_index]; // 读取网络层传入的数据
Mat top_blob;
int ret = layer->forward(bottom_blob, top_blob); // 具体网络层的前向传播
if (ret != 0)
return ret;
// store top blob
blob_mats[top_blob_index] = top_blob;
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。