1

I'd like to use the Caffe library to extract image features but I'm having performance issues. I can only use the CPU mode. I was told Caffe supported batch processing mode, in which the average time required to process one image was much slower.

I'm calling the following method:

const vector<Blob<Dtype>*>& 
Net::Forward(const vector<Blob<Dtype>* > & bottom, Dtype* loss = NULL);

and I'm putting in a vector of size 1, containing a single blob of the following dimensions - (num: 10, channels: 3, width: 227, height: 227). It represents a single image oversampled in the same way as in the official python wrapper.

This works and gives correct results. It is, however, too slow.

Whenever I try to send in a vector containing more than one blob (of the same dimensions), I get the following error:

F0910 16:10:14.848492 15615 blob.cpp:355] Trying to copy blobs of different sizes.
Check failure stack trace:

How do I make Caffe process my images in a batch?

Shai
  • 111,146
  • 38
  • 238
  • 371
Dušan Rychnovský
  • 11,699
  • 8
  • 41
  • 65

1 Answers1

2

If you want to feed larger batches you need the first (and only) blob in bottom to have num>10. Feeding a blob with num=20 is the same as feeding two inputs with oversample=10. You will, of course, have to perform the averaging manually according to the oversampling you are using.

Furthermore, you might want to change the first input dimension in your deploy.prototxt file from 10 to some larger value (depending on your machine's memory capacity)

Shai
  • 111,146
  • 38
  • 238
  • 371
  • So, in other words, there's no way to process a batch of images, without altering the definition of the network, correct? Because the network definition starts like this (the input blob dimensions are hardcoded there): name: "CaffeNet" input: "data" input_dim: 10 input_dim: 3 input_dim: 227 input_dim: 227 layers { ... – Dušan Rychnovský Sep 10 '15 at 14:43
  • @DušanRychnovský the network definition is used for memory allocation. You can change this "on the fly" using `Reshape` – Shai Sep 10 '15 at 14:47
  • 1
    Got it, thanks! :) It is confusing to me, though, that the signature of the Forward method expects a *vector* of blobs. What's the reason behind that if you can only ever feed vectors of size one? – Dušan Rychnovský Sep 10 '15 at 14:50
  • 2
    @DušanRychnovský some networks has more than one `"bottom"`, therefore you need a vector entry per `"bottom"`... – Shai Sep 10 '15 at 14:51