日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

Windows7 64bit VS2013 Caffe train MNIST操作步骤

發(fā)布時間:2023/11/27 生活经验 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Windows7 64bit VS2013 Caffe train MNIST操作步骤 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

?1.????????使用http://blog.csdn.net/fengbingchun/article/details/47905907中生成的Caffe靜態(tài)庫;

2.????????使用http://blog.csdn.net/fengbingchun/article/details/49794453中生成的LMDB數(shù)據(jù)庫文件;

3.????????新建一個train_mnist控制臺工程;

4.????????修改源文件中的caffe/examples/mnist/lenet_solver.prototxt文件:

(1)、net: "E:/GitCode/Caffe/src/caffe/caffe/examples/mnist/lenet_train_test.prototxt"

(2)、snapshot_prefix:"E:/GitCode/Caffe/src/caffe/caffe/examples/mnist/lenet"

(3)、solver_mode: CPU

5.????????修改源文件中的caffe/examples/mnist/lenet_train_test.prototxt文件,指定LMDB數(shù)據(jù)庫文件存放位置:

(1)、source:"E:/GitCode/Caffe/src/caffe/caffe/data/mnist/lmdb/train"

(2)、source:"E:/GitCode/Caffe/src/caffe/caffe/data/mnist/lmdb/test"

6.????????train_mnist.cpp文件中內容為(是對caffe/tools/caffe.cpp的修改):

#include "stdafx.h"
#include <iostream>#include <glog/logging.h>
#include <cstring>
#include <map>
#include <string>
#include <vector>#include "caffe/common.hpp"
#include "boost/algorithm/string.hpp"
#include "caffe/caffe.hpp"
#include "caffe/util/io.hpp"
#include "caffe/blob.hpp"
#include "caffe/layer_factory.hpp"
#include "boost/smart_ptr/shared_ptr.hpp"using caffe::Blob;
using caffe::Caffe;
using caffe::Net;
using caffe::Layer;
using caffe::Solver;
using caffe::shared_ptr;
using caffe::string;
using caffe::Timer;
using caffe::vector;
using std::ostringstream;DEFINE_string(solver, "E:/GitCode/Caffe/src/caffe/caffe/examples/mnist/lenet_solver.prototxt","The solver definition protocol buffer text file.");
DEFINE_string(snapshot, "E:/GitCode/Caffe/src/caffe/caffe/examples/mnist/lenet_iter_10000.solverstate","Optional; the snapshot solver state to resume training.");
DEFINE_string(weights, "E:/GitCode/Caffe/src/caffe/caffe/examples/mnist/xxxx.caffemodel","Optional; the pretrained weights to initialize finetuning, ""separated by ','. Cannot be set simultaneously with snapshot.");// A simple registry for caffe commands.
typedef int(*BrewFunction)();
typedef std::map<caffe::string, BrewFunction> BrewMap;
BrewMap g_brew_map;#define RegisterBrewFunction(func) \
namespace { \
class __Registerer_##func { \public: /* NOLINT */ \__Registerer_##func() { \g_brew_map[#func] = &func; \} \
}; \
__Registerer_##func g_registerer_##func; \
}static BrewFunction GetBrewFunction(const caffe::string& name) {if (g_brew_map.count(name)) {return g_brew_map[name];}else {LOG(ERROR) << "Available caffe actions:";for (BrewMap::iterator it = g_brew_map.begin(); it != g_brew_map.end(); ++it) {LOG(ERROR) << "\t" << it->first;}LOG(FATAL) << "Unknown action: " << name;return NULL;  // not reachable, just to suppress old compiler warnings.}
}// 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;boost::split(model_names, model_list, boost::is_any_of(","));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]);}}
}// Train / Finetune a model.
int train() {CHECK_GT(FLAGS_solver.size(), 0) << "Need a solver definition to train.";//CHECK(!FLAGS_snapshot.size() || !FLAGS_weights.size()) << "Give a snapshot to resume training or weights to finetune but not both.";caffe::SolverParameter solver_param;caffe::ReadProtoFromTextFileOrDie(FLAGS_solver, &solver_param);Caffe::set_mode(Caffe::CPU);shared_ptr<Solver<float> > solver(caffe::GetSolver<float>(solver_param));//if (FLAGS_snapshot.size()) { // resume training//	LOG(INFO) << "Resuming from " << FLAGS_snapshot;//	solver->Restore(FLAGS_snapshot.c_str());//}//else if (FLAGS_weights.size()) { // finetune//	CopyLayers(solver.get(), FLAGS_weights);//}LOG(INFO) << "Starting Optimization";solver->Solve();LOG(INFO) << "Optimization Done.";return 0;
}
RegisterBrewFunction(train);int main(int argc, char* argv[])
{argc = 2;
#ifdef _DEBUG  argv[0] = "E:/GitCode/Caffe/lib/dbg/x86_vc12/train_mnist[dbg_x86_vc12].exe";
#else  argv[0] = "E:/GitCode/Caffe/lib/rel/x86_vc12/train_mnist[rel_x86_vc12].exe";
#endif argv[1] = "train";// 每個進程中至少要執(zhí)行1次InitGoogleLogging(),否則不產(chǎn)生日志文件google::InitGoogleLogging(argv[0]);// 設置日志文件保存目錄,此目錄必須是已經(jīng)存在的FLAGS_log_dir = "E:\\GitCode\\Caffe";FLAGS_max_log_size = 1024;//MB// Print output to stderr (while still logging).FLAGS_alsologtostderr = 1;// Usage message.gflags::SetUsageMessage("command line brew\n""usage: caffe <command> <args>\n\n""commands:\n""  train           train or finetune a model\n");// Run tool or show usage.//caffe::GlobalInit(&argc, &argv);// 解析命令行參數(shù)  gflags::ParseCommandLineFlags(&argc, &argv, true);if (argc == 2) {return GetBrewFunction(caffe::string(argv[1]))();}else {gflags::ShowUsageWithFlagsRestrict(argv[0], "tools/caffe");}std::cout << "OK!!!" << std::endl;return 0;
}

7.????????執(zhí)行完train_mnist后會生成四個文件:lenet_iter_5000.caffemodel、lenet_iter_5000.solverstate、lenet_iter_10000.caffemodel、lenet_iter_10000.solverstate

8.????????運行結果如下圖:


GitHub:https://github.com/fengbingchun/Caffe_Test

總結

以上是生活随笔為你收集整理的Windows7 64bit VS2013 Caffe train MNIST操作步骤的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內容還不錯,歡迎將生活随笔推薦給好友。

歡迎分享!

轉載請說明來源于"生活随笔",并保留原作者的名字。

本文地址:Windows7 64bit VS2013 Caffe tr