版权声明:本文为博主原创文章,未经博主允许不得转载。 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 官方文档(一)- 开发者指南
- Boost:著名的c++准标准库,不多介绍。
- GFLAGS:命令行解析,用法非常简单,可查看源码
tools/caffe.cpp
。可参考:gflags(google开源的一套命令行参数解析工具) - GLOG:日志工具,也很简单。可查看源码
tools/caffe.cpp
。可参考:Google-glog 日志库使用手记 - BLAS:矩阵运算库。
- HDF5:数据存储格式。参考:HDF5 使用介绍,可参考caffe源码中hdf5.hpp和hdf5.cpp。
- OpenCV:著名的视觉库,不多介绍。
- LMDB和LEVELDB:在caffe中提供数据管理,将原始数据转换为键值对存储格式。参考LMDB简介
- Snappy:用来压缩和解压缩的c++库。参考:C++压缩解压之snappy