Caffe:Caffe依赖项

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/weixin_36049506/article/details/91394567

依赖项

  • ProtoBuffer:Google Protocol Buffer( 简称 Protobuf) 是 Google 公司内部的混合语言数据标准。
    Caffe源码中大量使用ProtoBuffer作为权值和模型参数的载体。ProtoBuffer还可以跨语言(C++/Java/Python)传递相同的数据结构。以C++为例,用户只需要编写参数描述文件.proto(caffe中为.prototxt),编译就会生成相应的类。然后,你可以在应用程序中使用此类来填充,序列化和检索自定义的参数。
    例子:
    在.proto文件定义一个数据结构
message Person {
  required string name = 1;
  required int32 id = 2;
  optional string email = 3;

  enum PhoneType {
    MOBILE = 0;
    HOME = 1;
    WORK = 2;
  }

  message PhoneNumber {
    required string number = 1;
    optional PhoneType type = 2 [default = HOME];
  }

  repeated PhoneNumber phone = 4;
}

然后可以在c++代码中使用编译生成的类:

//write
person.set_name("John Doe");
person.set_id(1234);
person.set_email("[email protected]");
fstream output("myfile", ios::out | ios::binary);
person.SerializeToOstream(&output);

//read
fstream input("myfile", ios::in | ios::binary);
Person person;
person.ParseFromIstream(&input);
cout << "Name: " << person.name() << endl;
cout << "E-mail: " << person.email() << endl;

更多细节看这篇文章:[翻译] ProtoBuf 官方文档(一)- 开发者指南

猜你喜欢

转载自blog.csdn.net/weixin_36049506/article/details/91394567