Ask Your Question
0

How can I load caffe-models that contain the file mean.binaryproto?

asked 2017-11-03 02:54:27 -0500

Rbt gravatar image

I have somes trained caffe-models that contain the file: "mean.binaryproto", so I need to read this file in order to sustract the mean value from input images. Is there any way to do that using OpenCV only?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2017-11-05 15:01:04 -0500

dkurt gravatar image

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

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.

edit flag offensive delete link more

Comments

@dkurt, i just tried the protobuf_parser and i got:

C:\p\ocv\dnn\protobuf_parser\samples>parse_caffe_model --caffemodel=C:\data\mdl\age\mean.binaryprotoC:\data\mdl\age\mean.binaryproto --proto=C:\data\mdl\age\mean.prototxt
OpenCV: terminate handler is called! The last OpenCV error is:
OpenCV(3.4.2-dev) Error: Parsing error (Unsupported wire type [6]) in parseKey, file src/proto_message.cpp, line 42

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.

in fact, i get this for any combination of caffemodel/prototxt i have on this box.

berak gravatar imageberak ( 2018-08-13 06:04:44 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2017-11-03 02:54:27 -0500

Seen: 486 times

Last updated: Nov 05 '17