当前位置: 首页>>代码示例>>C++>>正文


C++ Net::blob_by_name方法代码示例

本文整理汇总了C++中Net::blob_by_name方法的典型用法代码示例。如果您正苦于以下问题:C++ Net::blob_by_name方法的具体用法?C++ Net::blob_by_name怎么用?C++ Net::blob_by_name使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Net的用法示例。


在下文中一共展示了Net::blob_by_name方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: computeFeatures

void computeFeatures(Net<Dtype>& caffe_test_net,
    const vector<Mat>& imgs,
    string LAYER,
    int BATCH_SIZE,
    vector<vector<Dtype>>& output) {
  int nImgs = imgs.size();
  int nBatches = ceil(nImgs * 1.0f / BATCH_SIZE);
  for (int batch = 0; batch < nBatches; batch++) {
    int actBatchSize = min(nImgs - batch * BATCH_SIZE, BATCH_SIZE);
    vector<Mat> imgs_b;
    if (actBatchSize >= BATCH_SIZE) {
      imgs_b.insert(imgs_b.end(), imgs.begin() + batch * BATCH_SIZE, 
          imgs.begin() + (batch + 1) * BATCH_SIZE);
    } else {
      imgs_b.insert(imgs_b.end(), imgs.begin() + batch * BATCH_SIZE, imgs.end());
      for (int j = actBatchSize; j < BATCH_SIZE; j++)
        imgs_b.push_back(imgs[0]);
    }
    vector<int> dvl(BATCH_SIZE, 0);
    boost::dynamic_pointer_cast<caffe::MemoryDataLayer<Dtype>>(
        caffe_test_net.layers()[0])->AddMatVector(imgs_b, dvl);
    vector<Blob<Dtype>*> dummy_bottom_vec;
    Dtype loss = 0.0f;
    caffe_test_net.ForwardPrefilled(&loss);
    const boost::shared_ptr<Blob<Dtype>> feat = caffe_test_net.blob_by_name(LAYER);
    for (int i = 0; i < actBatchSize; i++) {
      Dtype* feat_data = feat->mutable_cpu_data() + feat->offset(i);
      output.push_back(vector<Dtype>(feat_data, feat_data + feat->count() / feat->num()));
    }
    LOG(INFO) << "Batch " << batch << "/" << nBatches << " (" << actBatchSize << " images) done";
  }
}
开发者ID:rohitgirdhar,项目名称:ComputeFeatures,代码行数:32,代码来源:utils.hpp

示例2: blob_get_data_byname_multigpu

// function blob_get_data_byname_multigpu
// input:  blob_name 
// output: response
static void blob_get_data_byname_multigpu(MEX_ARGS) {
	if (nrhs != 1) {
		LOG(ERROR) << "Only given " << nrhs << " arguments";
		mexErrMsgTxt("caffe_mex : Wrong number of arguments");
	}

	if (solvers_.empty())
	{
		mexPrintf("No solver inited!\n");
		plhs[0] = mxCreateDoubleScalar(-1);
		return;
	}

	mxCHECK(sync_ptr != NULL, "blob_set_data_multigpu only work on multi-GPU solver");

	vector<shared_ptr<P2PSync<float>>>* sync_vec = sync_ptr->get_syncs(); 

	char* blob_name = mxArrayToString(prhs[0]);

	mxArray* top;
	top = mxCreateCellMatrix(int(sync_vec->size()), 1);
	for (int i = 0; i < sync_vec->size(); i++)
	{
		Solver<float> *solver;
		if (i == 0)
		{
			solver = sync_ptr->solver().get();
		}
		else
		{
			solver = (*sync_vec)[i]->solver().get();
		}

		Net<float> *net = solver->net().get();
		Blob<float> *blob = net->blob_by_name(blob_name).get();

		mxArray* response = blob_to_mx_mat(blob, DATA);
		mxSetCell(top, i, response);
	}

	plhs[0] = top;
	mxFree(blob_name);
}
开发者ID:sciencefans,项目名称:caffe,代码行数:46,代码来源:caffe_.cpp


注:本文中的Net::blob_by_name方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。