caffe icon indicating copy to clipboard operation
caffe copied to clipboard

Multivariate regression

Open caffecuda opened this issue 12 years ago • 11 comments

Hello, Is it possible to do multivariate regression with Caffe i.e. the labels are in R^d? thanks.

caffecuda avatar Aug 07 '14 22:08 caffecuda

I've been investigating that for the past couple of days. Unfortunately the Datum definition only allows one dimensional data as a label. An alternative is to use the HDF data layer (#203) instead of a DB backend data layer. The HDF5 data definition allows n-dimensional labels; though the only problem with HDFLayer is that it doesn't provide mean subtraction functionality. You have to subtract the mean from your data prior to saving it. After you get past this, you can use something like Euclidean Loss in your network to do multivariate regression.

ashafaei avatar Aug 10 '14 02:08 ashafaei

While the DataLayer at present only allows a 1D label, you can simply define a model with two DataLayers. Caffe understands DAGs, so you first DataLayer will have a top "data" and your second will have a top "label" that can produce any 4D label you like or a label in R^d as a d x 1 x 1 x 1 blob.

Ask modeling questions on the caffe-users mailing list please!

shelhamer avatar Aug 27 '14 07:08 shelhamer

@shelhamer Hmm you say "the DataLayer at present only allows a 1D label". That's true, but it seems there is an even worse restriction, according to caffe.proto, it can only be a int32:

message Datum { // ... stuff omitted optional int32 label = 5; // ... }

In regression we normally want a float label.

So it seems to me we can't use the DB backend at all for regression with a 1D float label, right? We have to use HDF5?

elador avatar Oct 08 '14 21:10 elador

No: my suggestion was to use two data layers. One is for the data, and the other is for the label. Both now produce 4-D blobs with whatever dimension you want with float precision.

On Wednesday, October 8, 2014, elador [email protected] wrote:

@shelhamer https://github.com/shelhamer Hmm you say "the DataLayer at present only allows a 1D label". That's true, but it seems there is an even worse restriction, according to caffe.proto, it can only be a int32:

message Datum { // ... stuff omitted optional int32 label = 5; // ... }

In regression we normally want a float label.

So it seems to me we can't use the DB backend at all for regression with a 1D float label, right? We have to use HDF5?

— Reply to this email directly or view it on GitHub https://github.com/BVLC/caffe/issues/881#issuecomment-58432853.

shelhamer avatar Oct 08 '14 22:10 shelhamer

sorry, I tried two data layer. One is for the data, and the other is for the label. but, I don't know how to pick the same indices for a given batch from these 2 data layer ?

daphneLin0618 avatar Oct 14 '14 09:10 daphneLin0618

In any case if someone is interested I have changed manually to allow the label to be a float using the "lmdb" database format.

I have modified the convert_imageset.cpp (int for float): std::vector<std::pair<std::string, float> > lines; std::string filename; float label;

In caffe.proto (int for float) message Datum { optional int32 channels = 1; ... optional float label = 5; .... optional bool encoded = 7 [default = false]; }

In io.cpp and io.h (int for float) bool ReadImageToDatum(const string& filename, const float label, const int height, const int width, const bool is_color, Datum* datum)

And currently I have the database in format "lmdb" with the label as float between [0,1].

ivanhc avatar Dec 02 '14 16:12 ivanhc

I do have the same problem as daphneLin0618

I use layers { name: "mnist" type: HDF5_DATA top: "data" top: "label" hdf5_data_param { source: "sample_data_list.txt" batch_size: 64 } include: { phase: TRAIN } } layers { name: "mnist2" type: HDF5_DATA top: "data_output" top: "label2" hdf5_data_param { source: "sample_data_list2.txt" batch_size: 64 } include: { phase: TRAIN } }

and want to use data_output 2 as a multidimensional "label", data output I have a net working on "data" and want to train the result with "data_output",

but if I run it I get training reports from both layers, they do not seem synced?!

I1225 13:24:19.921097 32508 solver.cpp:206] Train net output #60: label = 4013 I1225 13:24:19.921105 32508 solver.cpp:206] Train net output #61: label = 4014 I1225 13:24:19.921113 32508 solver.cpp:206] Train net output #62: label = 4015 I1225 13:24:19.921121 32508 solver.cpp:206] Train net output #63: label = 4016 I1225 13:24:19.921130 32508 solver.cpp:206] Train net output #64: label2 = 3953 I1225 13:24:19.921139 32508 solver.cpp:206] Train net output #65: label2 = 3954 I1225 13:24:19.921147 32508 solver.cpp:206] Train net output #66: label2 = 3955 I1225 13:24:19.921155 32508 solver.cpp:206] Train net output #67: label2 = 3956 I1225 13:24:19.921164 32508 solver.cpp:206] Train net output #68: label2 = 3957

dsmic avatar Dec 25 '14 12:12 dsmic

Suppose I use a list text file for my dataset like this with one line per traing sample: "image_file_name regression_vector classified_id regression_vector2"

for example:

         "path/to/image.jpg 0.54   2.34   4.56  4  5.60  7.45"

My question is : how to feed the dataset to caffe ( or convert to caffe accepted format such as LMDB)?

Thanks,

wguo68 avatar Feb 06 '15 07:02 wguo68

@wguo68 : Did you figure out if this is the right format? I'd greatly appreciate if you could share a little on how you fed this to Caffe. Thanks!

anguyen8 avatar Jun 19 '15 18:06 anguyen8

Hmm, sorry, you probably did not mean me? dmic seems to be somebody else?!

I use dsmic? Or I do not remember what it was about:)

Detlef

Am 19.06.2015 um 20:31 schrieb Anh Nguyen [email protected]:

@wguo68 : Did you figure out if this is the right format? I'd greatly appreciate if you could share a little on how you fed this to Caffe?

— Reply to this email directly or view it on GitHub.

dsmic avatar Jun 19 '15 18:06 dsmic

@dsmic : Ah no, I meant @wguo68 . Thanks for asking. :)

anguyen8 avatar Jun 22 '15 20:06 anguyen8