0

I search the Caffe source code a bit, and the ReadImageToDatum function in caffe/src/caffe/util/io.cpp only supports int type labels.

I've also noticed that there's an array_to_datum function in caffe/python/caffe/io.py, which seems to not have the constraint on the type of label, but I'm not exactly sure how I'm supposed to use it.

How can I use numerical (non-integers) labels for regression?

Shai
  • 111,146
  • 38
  • 238
  • 371
dontloo
  • 10,067
  • 4
  • 29
  • 50

2 Answers2

1

I suppose Datum type was designed with image classification in mind.
For regression, I recommend using "HDF5Data" input layer.
See this answer for example.

Using hdf5 binary files allows for more flexibility in the number, shape and type of inputs you feed your net.

Community
  • 1
  • 1
Shai
  • 111,146
  • 38
  • 238
  • 371
  • thank you much for answering, would you have any thoughts on [this question](http://stackoverflow.com/q/38432568/3041068)? – dontloo Jul 20 '16 at 06:32
1

In addition to Shai's answer, caffe's Datum class only support int type labels. In caffe/src/caffe/proto/caffe.proto it is defined

message Datum {
  optional int32 channels = 1;
  optional int32 height = 2;
  optional int32 width = 3;
  // the actual image data, in bytes
  optional bytes data = 4;
  optional int32 label = 5;
  // Optionally, the datum could also hold float data.
  repeated float float_data = 6;
  // If true data contains an encoded image that need to be decoded
  optional bool encoded = 7 [default = false];
}

So in the generated caffe.pb.h file it's like

private:
  ...
  ::google::protobuf::int32 channels_;
  ::google::protobuf::int32 height_;
  ::std::string* data_;
  ::google::protobuf::int32 width_;
  ::google::protobuf::int32 label_;
  ::google::protobuf::RepeatedField< float > float_data_;
  bool encoded_;
  ...
Community
  • 1
  • 1
dontloo
  • 10,067
  • 4
  • 29
  • 50