将GpuMat与Caffe一起使用

时间:2018-06-27 01:17:05

标签: c++ gpu caffe opencv3.0

在标准咖啡因example code here中,我们有:

void Classifier::WrapInputLayer(std::vector<cv::Mat>* input_channels) {
  Blob<float>* input_layer = net_->input_blobs()[0];

  int width = input_layer->width();
  int height = input_layer->height();
  float* input_data = input_layer->mutable_cpu_data();
  for (int i = 0; i < input_layer->channels(); ++i) {
    cv::Mat channel(height, width, CV_32FC1, input_data);
    input_channels->push_back(channel);
    input_data += width * height;
  }
}

如果我使用cv::cuda::GpuMat,可以重写代码吗?

void Classifier::WrapInputLayer(std::vector<cv::cuda::GpuMat>* input_channels) {
  Blob<float>* input_layer = net_->input_blobs()[0];

  int width = input_layer->width();
  int height = input_layer->height();
  float* input_data = input_layer->mutable_gpu_data();
  for (int i = 0; i < input_layer->channels(); ++i) {
    cv::cuda::GpuMat channel(height, width, CV_32FC1, input_data); // OK I hope?
    input_channels->push_back(channel);
    input_data += width * height;
  }
}

我们在这里使用this GpuMat constructor for initialising to a GPU memory pointer。然后可以Preprocess()更新为使用OpenCV界面的相关GPU版本。

有没有陷阱等着我?

注意:我刚刚进行了更改,它似乎可以按预期运行,但是当我通过Google查看时,该主题的信息匮乏,因此也许可以作为一个规范例子吗?

0 个答案:

没有答案