caffe icon indicating copy to clipboard operation
caffe copied to clipboard

Maximum label dimension and how to model problems with 2+ dimensions

Open mauinz opened this issue 12 years ago • 3 comments

Hi, from what I've read about caffe and the HDF5 data layers, it seems the label dimension is capped at 2. If I understand this correctly, since our first dimension defines where in our batch we are this means for any training image we can only have a 1D vector for regression.

If this is the case I'm curious as to why this cap was enforced. Of course we could get around this by flattening any none 1D label but that seems rather inelegant.

I could be understanding the code wrong so please correct me if this is the case.

edit: Having thought a bit more, has this been done as you assume the final layer (pre label) will be fully connected?

mauinz avatar Oct 21 '14 17:10 mauinz

Caffe on the whole represents data as "blobs" that are essentially 4-D matrices. Input, output, and intermediates communicated between layers are all 4-D. The "data" and "label" are both blobs and so inherently 4-D. Loss layers such as SoftmaxWithLossLayer, EuclideanLossLayer, and SigmoidCrossEntropyLossLayer only require the prediction / output (bottom 1) and target / label (bottom 2) have the same shape. To learn a k-D problem, define a model with k-D output and k-D truth for k in {1, 2, 3, 4}, prepare the data, and brew.

See for instance Euclidean loss Forward to see that there is no restriction on output and target dimension other than matching (and that they are blobs).

The cap on label dimensions you've noted is only a limitation of bundled tools like convert_imageset and not the framework and its models. The 2-D labels of dimensions batch x label x 1 x 1 are just a common special case. To transcend this special case sidestep the tools and prepare the input DB / HDF5 directly. One can for instance generate a LMDB in Python. In the model, define a data layer for each source such as (1) an input image and (2) a depth map if one wants to regress to depth at every pixel for example.

The limitation on HDF5DataLayer was incidental and has since been lifted in dev: https://github.com/BVLC/caffe/blob/dev/src/caffe/layers/hdf5_data_layer.cpp#L35-L45. It now loads any number of top blobs of 1-4 dimensions.

This deserves better documentation and will be clarified after the CVPR deadline once the developers decompress.

shelhamer avatar Oct 21 '14 19:10 shelhamer

Ah I see, you're right, I was looking at the master branch. I'll pull and make the dev branch in that case!

Thanks for clarifying and good luck with your CVPR submissions!

mauinz avatar Oct 21 '14 20:10 mauinz

@shelhamer You said:

To learn a k-D problem, define a model with k-D output and k-D truth for k in {1, 2, 3, 4}, prepare the data, and brew

How do you create a k-D output? I thought the only output you have is a loss layer and accuracy layer for the test phase?

henzler avatar Oct 31 '16 16:10 henzler