在caffe中,从二进制文件中读取message 参数

怎么使用?

3.ReadProtoFromBinaryFile 函数:

这里有个链接:

点击打开链接 解释caffe函数


假如 你已经安装好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文件。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Teleger

你的支持是我前进的方向

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值