Single Float label , LMDB Format in caffe

539 views Asked by At

I am using caffe for a regression problem and I want to know how is possible to use format for single float label.

Right now, caffe only supports int32 type label for lmdb data (type of label in Datum is int32).
In order to change this default behavior, I changed some of files in caffe as follows but the problem has stayed and after converting my labels all are zero.

caffe.proto -> line36 : int32 to float
convert_imageset.cpp -> line 75 and 77 : int to float
io.cpp and io.hpp -> all the labels were int , I changed them to float 

After all I compiled caffe again but it doesn't work.

Is there anyone to solve this problem. it is very important to me to solve it as soon as possible.

Thanks in advance.

2

There are 2 answers

3
Shai On BEST ANSWER

If you insist to force caffe to support float labels, you might need to change convert_imageset.cpp line 81 as well.
Currently this line uses atoi to convert string to int:

label = atoi(line.substr(pos + 1).c_str());

You should convert it to user atof to convert string to float:

label = atof(line.substr(pos + 1).c_str());
1
Shai On

Solving your problem by forcing and tweaking caffe to work with float labels in LMDB dataset seems like not a very good strategy.

I suggest instead to use caffe's "HDF5Data" layer. Using hdf5 format to store data for caffe is much more flexible and allows you to have float labels.

For more information see this answer.