如何在 Caffe 中使用数字标签进行回归?

How can I use numerical labels for regression in Caffe?

查了一下Caffe源码,caffe/src/caffe/util/io.cpp中的ReadImageToDatum函数只支持int类型的标签

我也注意到caffe/python/caffe/io.py里有一个array_to_datum函数,好像对label的类型没有限制,不过我也不太清楚应该使用它。

如何使用数字(非整数)标签进行回归?

我想 Datum type 是为图像分类而设计的。
对于回归,我建议使用 "HDF5Data" 输入层。
例如,参见

使用 hdf5 二进制文件可以更灵活地输入网络的数量、形状和类型。

除了,caffe的Datumclass只支持int类型的标签。 在caffe/src/caffe/proto/caffe.proto中定义

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];
}

所以在生成的 caffe.pb.h 文件中它就像

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_;
  ...