今天看caffe库, 在caffe.cpp 中看到boost库中split函数,今天特意总结一下这个函数用法。
在caffe.cpp的使用如下:
// Load the weights from the specified caffemodel(s) into the train and
// test nets.
void CopyLayers(caffe::Solver<float>* solver, const std::string& model_list) {
std::vector<std::string> model_names;
<span style="background-color: rgb(255, 0, 0);"> boost::split(model_names, model_list, boost::is_any_of(",") );</span>
for (int i = 0; i < model_names.size(); ++i) {
LOG(INFO) << "Finetuning from " << model_names[i];
solver->net()->CopyTrainedLayersFrom(model_names[i]);
for (int j = 0; j < solver->test_nets().size(); ++j) {
solver->test_nets()[j]->CopyTrainedLayersFrom(model_names[i]);
}
}
}
这个库的详细使用如下:
工程中使用boost库:(设定vs2010环境)
在Library files加上 D:\boost\boost_1_46_0\bin\vc10\lib
在Include files加上 D:\boost\boost_1_46_0
使用举例:
- // boostTest.cpp : 定义控制台应用程序的入口点。
- #include "stdafx.h"
- #include <iostream>
- #include <boost/format.hpp>
- #include <boost/tokenizer.hpp>
- #include <boost/algorithm/string.hpp>
- int _tmain(int argc, _TCHAR* argv[])
- {
- std::wcout.imbue(std::locale("chs"));
- //待分割的字符串
- std::wstring strTag = _T("I Come from China");
- std::vector<std::wstring> vecSegTag;
- // boost::is_any_of这里相当于分割规则了
- boost::split(vecSegTag, strTag,boost::is_any_of(_T(" ,,")));
- for (size_t i =0;i<vecSegTag.size();i++)
- {
- std::wcout<<vecSegTag[i]<<std::endl;
- }
- vecSegTag.clear();
- std::wstring strTag2 = _T("我叫小马,你呢,今天天气不错,我很高兴");
- boost::split(vecSegTag, strTag2, boost::is_any_of(_T(" ,,")));
- for (size_t i =0 ; i<vecSegTag.size(); i++)
- {
- std::wcout<<vecSegTag[i]<<std::endl;
- }
- getchar();
- return 0;
- }
使用boost库 写程序特别方便。