【问题标题】:How can I use numerical labels for regression in Caffe?如何在 Caffe 中使用数字标签进行回归?
【发布时间】:2016-07-20 14:50:08
【问题描述】:

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

我还注意到caffe/python/caffe/io.py 中有一个array_to_datum 函数,它似乎对标签的类型没有限制,但我不确定我应该如何使用它。

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

【问题讨论】:

    标签: machine-learning neural-network deep-learning caffe


    【解决方案1】:

    我想Datum 类型的设计考虑了图像分类。
    对于回归,我建议使用"HDF5Data" 输入层。
    例如,请参阅this answer

    使用 hdf5 二进制文件可以让您在输入网络的数量、形状和类型方面更加灵活。

    【讨论】:

    • 非常感谢您的回答,您对this question有什么想法吗?
    【解决方案2】:

    除了Shai's answer,caffe 的Datum 类只支持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_;
      ...
    

    【讨论】:

      猜你喜欢
      • 2017-04-19
      • 2016-01-18
      • 1970-01-01
      • 2017-03-09
      • 2016-07-22
      • 2017-01-21
      • 1970-01-01
      • 2019-04-02
      • 2018-09-21
      相关资源
      最近更新 更多