Blobs

153 views
Skip to first unread message

Christopher Turnbull

unread,
Feb 8, 2016, 7:17:43 AM2/8/16
to Caffe Users

From the website...


"A Blob is a wrapper over the actual data being processed and passed along by Caffe, and also under the hood provides synchronization capability between the CPU and the GPU. Mathematically, a blob is an N-dimensional array stored in a C-contiguous fashion.

Caffe stores and communicates data using blobs. Blobs provide a unified memory interface holding data; e.g., batches of images, model parameters, and derivatives for optimization.

Blobs conceal the computational and mental overhead of mixed CPU/GPU operation by synchronizing from the CPU host to the GPU device as needed. Memory on the host and device is allocated on demand (lazily) for efficient memory usage.

The conventional blob dimensions for batches of image data are number N x channel K x height H x width W. Blob memory is row-major in layout, so the last / rightmost dimension changes fastest. For example, in a 4D blob, the value at index (n, k, h, w) is physically located at index ((n * K + k) * H + h) * W + w....."


Could someone explain this a little simpler for me? I take it that blobs are the 'labels' describing the data as it runs from layer to layer?

Jan C Peters

unread,
Feb 8, 2016, 9:40:32 AM2/8/16
to Caffe Users
The concept of a blob is a technical one and not directly related to the theory of neural networks. I don't think I can put it any more precise than the description you cited, but I will try:
  1. Blobs are containers of data. They have two main uses:
    1. To store the results of layer computations (like convolutions, inner products, activation functions), I guess this is what you mean by "'labels' describing the data as it runs from layer to layer": intermediary results of the complete network's computation (inputs and outputs are stored in blobs as well).
    2. To store the trainable parameters of the layers themselves, such as convolution filter kernels, weight matrices, biases,...
  2. A blob is basically just a multidimensional array. Actually two arrays, one for data (filled in forward pass of the network) and one for diff (filled during backward pass and used to update weights).
  3. Blobs only hold data, they do not manipulate it. That is the task of the layers and the solver.
  4. You don't have to care about whether the array(s) are actually stored in the RAM or VRAM, the underlying architecture copies it around as needed.
  5. The 1.1 kind of blobs has names, the 1.2 kind does not. The names are used to associate output of one layer to input of another layer.
  6. Blobs are created implicitly from your network.prototxt config file, the 1.1 kind by mentioning them by name as a top or bottom blob of a layer, and the 1.2 kind simply by specifying a "layer" instance.
  7. In standard convolutional networks working with 2D images, input blobs have the shape (N,K,H,W) as described above. But the dimensions a blob has are pretty much arbitrary. It can even consist of only one number; that is the case for a top blob of an accuracy layer for instance.
As a user of caffe, not all of these things need to be of interest to you, but usually it is good to know what goes on under the hood.

Hope that helps.

Jan

Christopher Turnbull

unread,
Feb 8, 2016, 10:12:23 AM2/8/16
to Caffe Users
Ah I see, so it's just an N-dimensional array. What does it mean by it's stored "in a C-contiguous fashion...?" and what kinds of parameters are stored in it?

Jan C Peters

unread,
Feb 10, 2016, 3:15:10 AM2/10/16
to Caffe Users
To store an N-dimensional array in a memory space that is addressed linearly (as it always is with memory on computers), you need to serialize it. The most natural way for a 2D array, for instance, is to first store the first row, then the second row and so on. This is called row-major storage. The other popular way is to store by columns. Both concepts can be extended to an arbitrary number of dimensions. C-contiguous means row-major storage. Also there is no padding or other additional data at the end of every row, only the raw array data.

As for "what is stored in it": I said that already. Per se it is just a container and can store any numeral data. It is used to store intermediate computations of layers, weights and biases of these layers and other parameters that are trainable.

Jan
Reply all
Reply to author
Forward
0 new messages