您的位置:首页 > Web前端

caffe之SSD算法词袋解析

2017-07-27 00:20 211 查看
text解析接口函数:

https://developers.google.com/protocol-buffers/docs/reference/cpp/google.protobuf.text_format

代码如下:

#include "caffe/proto/caffe.pb.h"
#include <caffe/caffe.hpp>
#include <iostream>
#include <fstream>
#include <string>
#include <fcntl.h>
#include <google/protobuf/io/coded_stream.h>
#include <google/protobuf/io/zero_copy_stream_impl.h>
#include <google/protobuf/text_format.h>

using namespace caffe;
using namespace std;

int main(int argc, char const *argv[]){
LabelMap labelmap;
int fd = open(argv[1], O_RDONLY | 0);
CHECK_NE(fd, -1) << "File not found: " << argv[1];
google::protobuf::io::FileInputStream fileInput(fd);
fileInput.SetCloseOnDelete( true );
bool success = google::protobuf::TextFormat::Merge(&fileInput,&labelmap);
for(int i = 0; i < labelmap.item_size(); i++)
{
const LabelMapItem&  vociterm = labelmap.item(i);
cout<< "Name:"<< vociterm.name() << endl;
cout<<"label:"<< vociterm.label() << endl;
cout<<"display_name:"<<vociterm.display_name()<< endl;
}
close(fd);
return success;
}


makefile文件如下:

CAFFEROOT=../../deeplearning/ssd/caffe

CAFFEINC=-I$(CAFFEROOT)/include\
-I$(CAFFEROOT)/build/src\
-I/usr/local/Cellar/openblas/0.2.19_1/include\
-I./include

CAFFELIB=-L$(CAFFEROOT)/build/lib\
-L/usr/local/lib\
-lcaffe -lglog -lboost_system -lgflags -lprotobuf

CAFFEFLAGS=-D CPU_ONLY

OPENCVINC=$(shell pkg-config opencv --cflags)
OPENCVLIBS=$(shell pkg-config opencv --libs)

SRC=parse_caffe_itermap.cpp

all:
g++ -o parse_voc $(SRC) $(CAFFEFLAGS) $(CAFFELIB) $(CAFFEINC) $(OPENCVINC) $(OPENCVLIBS)
clean:
rm -rf parse_voc
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: