Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

@Rbt, we can try to use an experimental OpenCV's protobuf parser: https://github.com/opencv/opencv_contrib/pull/1291.

Create a text file with the following content (describes BlobProto message structure):

file {
  name: "caffe.proto"
  package: "caffe"
  message_type {
    name: "BlobShape"
    field {
      name: "dim"
      number: 1
      label: LABEL_REPEATED
      type: TYPE_INT64
      options {
        packed: true
      }
      json_name: "dim"
    }
  }
  message_type {
    name: "BlobProto"
    field {
      name: "shape"
      number: 7
      label: LABEL_OPTIONAL
      type: TYPE_MESSAGE
      type_name: ".caffe.BlobShape"
      json_name: "shape"
    }
    field {
      name: "data"
      number: 5
      label: LABEL_REPEATED
      type: TYPE_FLOAT
      options {
        packed: true
      }
      json_name: "data"
    }
    field {
      name: "diff"
      number: 6
      label: LABEL_REPEATED
      type: TYPE_FLOAT
      options {
        packed: true
      }
      json_name: "diff"
    }
    field {
      name: "double_data"
      number: 8
      label: LABEL_REPEATED
      type: TYPE_DOUBLE
      options {
        packed: true
      }
      json_name: "doubleData"
    }
    field {
      name: "double_diff"
      number: 9
      label: LABEL_REPEATED
      type: TYPE_DOUBLE
      options {
        packed: true
      }
      json_name: "doubleDiff"
    }
    field {
      name: "raw_data_type"
      number: 10
      label: LABEL_OPTIONAL
      type: TYPE_ENUM
      type_name: ".caffe.Type"
      json_name: "rawDataType"
    }
    field {
      name: "raw_data"
      number: 12
      label: LABEL_OPTIONAL
      type: TYPE_BYTES
      options {
        packed: false
      }
      json_name: "rawData"
    }
    field {
      name: "num"
      number: 1
      label: LABEL_OPTIONAL
      type: TYPE_INT32
      default_value: "0"
      json_name: "num"
    }
    field {
      name: "channels"
      number: 2
      label: LABEL_OPTIONAL
      type: TYPE_INT32
      default_value: "0"
      json_name: "channels"
    }
    field {
      name: "height"
      number: 3
      label: LABEL_OPTIONAL
      type: TYPE_INT32
      default_value: "0"
      json_name: "height"
    }
    field {
      name: "width"
      number: 4
      label: LABEL_OPTIONAL
      type: TYPE_INT32
      default_value: "0"
      json_name: "width"
    }
  }
}

Initialize ProtobufParser with the path to created file and top message type .caffe.BlobProto. Also set text flag is true. Than call method parse with the path to .binaryproto. Print out all "data" values. The sample might help. I described it very briefly so let us know if something won't work.