怎么使用?
3.ReadProtoFromBinaryFile 函数:
这里有个链接:
假如 你已经安装好caffe ,好 ,
~ 为你的用户名。
/home/~/caffe 假定 这个是你caffe的安装目录.
假定 你 打算用cpp 的方式编译 运行, 好,请到这个目录下,
/home/~/caffe/examples/cpp_classification
下面是使用代码:
#include <caffe/caffe.hpp>
#include <google/protobuf/io/coded_stream.h>
#include <google/protobuf/io/zero_copy_stream_impl.h>
#include <google/protobuf/text_format.h>
#include <algorithm>
#include <iosfwd>
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include <iostream>
#include "caffe/common.hpp"
#include "caffe/proto/caffe.pb.h"
#include "caffe/util/io.hpp"
using namespace caffe;
using namespace std;
using google::protobuf::io::FileInputStream;
using google::protobuf::io::FileOutputStream;
using google::protobuf::io::ZeroCopyInputStream;
using google::protobuf::io::CodedInputStream;
using google::protobuf::io::ZeroCopyOutputStream;
using google::protobuf::io::CodedOutputStream;
using google::protobuf::Message;
int main(int argc, char const *argv[])//"/home/~/caffe/build-to/style_transfer_svic1212_iter41005_3bits.caffemodel"
{
NetParameter proto;
bool bread = ReadProtoFromBinaryFile(argv[1], &proto);
if (bread) {
WriteProtoToTextFile(proto,argv[2]);//"/home/~/caffe/build-to/Mess.txt"
std::cout << "WriteProto succeed exit" << std::endl;
}
return 0;
}
保存上面代码xx.cpp, 然后重新 make ,就可以在 caffe/build/examples/cpp_classification/ 下找到对应的bin 文件,运行即可。
解释下,上面代码:
main 函数,需接受 2个参数,1个是bin模型文件,1个是写入 的txt文件。