caffe之SSD算法词袋解析

来源:互联网 发布:手动安装windows补丁 编辑:程序博客网 时间:2024/04/19 17:01

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/caffeCAFFEINC=-I$(CAFFEROOT)/include\         -I$(CAFFEROOT)/build/src\         -I/usr/local/Cellar/openblas/0.2.19_1/include\         -I./includeCAFFELIB=-L$(CAFFEROOT)/build/lib\     -L/usr/local/lib\     -lcaffe -lglog -lboost_system -lgflags -lprotobufCAFFEFLAGS=-D CPU_ONLYOPENCVINC=$(shell pkg-config opencv --cflags)  OPENCVLIBS=$(shell pkg-config opencv --libs)  SRC=parse_caffe_itermap.cppall:    g++ -o parse_voc $(SRC) $(CAFFEFLAGS) $(CAFFELIB) $(CAFFEINC) $(OPENCVINC) $(OPENCVLIBS)clean:    rm -rf parse_voc
原创粉丝点击