caffe命令及其参数解析
caffe的c++主程序(caffe.cpp)放在根目录下的tools文件夹内, 当然还有一些其它的功能文件,如:convert_imageset.cpp, train_net.cpp, test_net.cpp等也放在这个文件夹内。经过编译后,这些文件都被编译成了可执行文件,放在了 ./build/tools/ 文件夹内。因此我们要执行caffe程序,都需要加 ./build/tools/ 前缀。
如:
# sudo sh ./build/tools/caffe train --solver=examples/mnist/train_lenet.sh
caffe程序的命令行执行格式如下:
caffe <command> <args>
其中的<command>有这样四种:
- train
- test
- device_query
- time
对应的功能为:
train----训练或finetune模型(model),
test-----测试模型
device_query---显示gpu信息
time-----显示程序执行时间
其中的<args>参数有:
- -solver
- -gpu
- -snapshot
- -weights
- -iteration
- -model
- -sighup_effect
- -sigint_effect
注意前面有个-符号。对应的功能为:
-solver:必选参数。一个protocol buffer类型的文件,即模型的配置文件。如:
# ./build/tools/caffe train -solver examples/mnist/lenet_solver.prototxt
-gpu: 可选参数。该参数用来指定用哪一块gpu运行,根据gpu的id进行选择,如果设置为'-gpu all'则使用所有的gpu运行。如使用第二块gpu运行:
# ./build/tools/caffe train -solver examples/mnist/lenet_solver.prototxt -gpu 2
-snapshot:可选参数。该参数用来从快照(snapshot)中恢复训练。可以在solver配置文件设置快照,保存solverstate。如:
# ./build/tools/caffe train -solver examples/mnist/lenet_solver.prototxt -snapshot examples/mnist/lenet_iter_5000.solverstate
-weights:可选参数。用预先训练好的权重来fine-tuning模型,需要一个caffemodel,不能和-snapshot同时使用。如:
# ./build/tools/caffe train -solver examples/finetuning_on_flickr_style/solver.prototxt -weights models/bvlc_reference_caffenet/bvlc_reference_caffenet.caffemodel
-iterations: 可选参数,迭代次数,默认为50。 如果在配置文件文件中没有设定迭代次数,则默认迭代50次。
-model:可选参数,定义在protocol buffer文件中的模型。也可以在solver配置文件中指定。
-sighup_effect:可选参数。用来设定当程序发生挂起事件时,执行的操作,可以设置为snapshot, stop或none, 默认为snapshot
-sigint_effect: 可选参数。用来设定当程序发生键盘中止事件时(ctrl+c), 执行的操作,可以设置为snapshot, stop或none, 默认为stop
刚才举例了一些train参数的例子,现在我们来看看其它三个<command>:
test参数用在测试阶段,用于最终结果的输出,要模型配置文件中我们可以设定需要输入accuracy还是loss. 假设我们要在验证集中验证已经训练好的模型,就可以这样写
# ./build/tools/caffe test -model examples/mnist/lenet_train_test.prototxt -weights examples/mnist/lenet_iter_10000.caffemodel -gpu 0 -iterations 100
这个例子比较长,不仅用到了test参数,还用到了-model, -weights, -gpu和-iteration四个参数。意思是利用训练好了的权重(-weight),输入到测试模型中(-model),用编号为0的gpu(-gpu)测试100次(-iteration)。
time参数用来在屏幕上显示程序运行时间。如:
# ./build/tools/caffe time -model examples/mnist/lenet_train_test.prototxt -iterations 10
这个例子用来在屏幕上显示lenet模型迭代10次所使用的时间。包括每次迭代的forward和backward所用的时间,也包括每层forward和backward所用的平均时间。
# ./build/tools/caffe time -model examples/mnist/lenet_train_test.prototxt -gpu 0
这个例子用来在屏幕上显示lenet模型用gpu迭代50次所使用的时间。
# ./build/tools/caffe time -model examples/mnist/lenet_train_test.prototxt -weights examples/mnist/lenet_iter_10000.caffemodel -gpu 0 -iterations 10
利用给定的权重,利用第一块gpu,迭代10次lenet模型所用的时间。
device_query参数用来诊断gpu信息。
# ./build/tools/caffe device_query -gpu 0
最后,我们来看两个关于gpu的例子
# ./build/tools/caffe train -solver examples/mnist/lenet_solver.prototxt -gpu 0,1
# ./build/tools/caffe train -solver examples/mnist/lenet_solver.prototxt -gpu all
这两个例子表示: 用两块或多块GPU来平行运算,这样速度会快很多。但是如果你只有一块或没有gpu, 就不要加-gpu参数了,加了反而慢。
最后,在linux下,本身就有一个time命令,因此可以结合进来使用,因此我们运行mnist例子的最终命令是(一块gpu):
$ sudo time ./build/toos/caffe train -solver examples/mnist/lenet_solver.prototxt
caffe命令及其参数解析的更多相关文章
- python命令行参数解析模块argparse和docopt
http://blog.csdn.net/pipisorry/article/details/53046471 还有其他两个模块实现这一功能,getopt(等同于C语言中的getopt())和弃用的o ...
- gflags命令行参数解析
gflags库是google开源的命令行参数解析工具. 安装 官方没有提供二进制库,但是Debian/Ubuntu平台本身提供了二进制库,可以直接git clone https://github.co ...
- [Go] 命令行参数解析包(flag 包)使用详解
Go 的 flag 包可以解析命令行的参数. 一.命令行语法 命令行语法主要有以下几种形式: cmd -flag // 只支持bool类型 cmd -flag=xxx cmd -flag ...
- $命令行参数解析模块argparse的用法
argparse是python内置的命令行参数解析模块,可以用来为程序配置功能丰富的命令行参数,方便使用,本文总结一下其基本用法. 测试脚本 把以下脚本存在argtest.py文件中: # codin ...
- Google开源命令行参数解析库gflags
Google开源命令行参数解析库gflags http://blog.csdn.net/lming_08/article/details/25072899 CMDLINE的解析 http://blog ...
- PHP 命令行参数解析工具类
<?php/** * 命令行参数解析工具类 * @author guolinchao * @email luoyecb@163.com */class CommandLine{ // store ...
- golang-flag - 命令行参数解析
flag - 命令行参数解析 在写命令行程序(工具.server)时,对命令参数进行解析是常见的需求.各种语言一般都会提供解析命令行参数的方法或库,以方便程序员使用.如果命令行参数纯粹自己写代码解析, ...
- Python命令行参数解析模块getopt使用实例
Python命令行参数解析模块getopt使用实例 这篇文章主要介绍了Python命令行参数解析模块getopt使用实例,本文讲解了使用语法格式.短选项参数实例.长选项参数实例等内容,需要的朋友可以参 ...
- python命令行参数解析OptionParser类用法实例
python命令行参数解析OptionParser类用法实例 本文实例讲述了python命令行参数解析OptionParser类的用法,分享给大家供大家参考. 具体代码如下: from opt ...
随机推荐
- WPF silverlight获取子控件(获取DataTemplate里的子控件)
public static class VisualTreeExtensions { /// <summary> /// 获取父节点控件 /// </summary> /// ...
- Codeforces Round #261 (Div. 2)459A. Pashmak and Garden(数学题)
题目链接:http://codeforces.com/problemset/problem/459/A A. Pashmak and Garden time limit per test 1 seco ...
- Linux系统安装Redis数据库
Redis redis是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对更多,包括string(字符串).list(链表).set(集合).zset(sorte ...
- JTextArea 加入滚动条
JTextArea texA; JScrollPane scroll; TextEdit(String name){ super(name); init(); } void init(){ this. ...
- 深入理解 JavaScript 异步——转载
本文章转载于深入理解 JavaScript 异步 前言 2014年秋季写完了<深入理解javascript原型和闭包系列>,已经帮助过很多人走出了 js 原型.作用域.闭包的困惑,至今仍能 ...
- Thread-local storage
Thread-local storage (TLS) is a computer programming method that uses static or global memory local ...
- BZOJ2161: 布娃娃 整体二分
Code: #include <cstdio> #include <algorithm> #include <cstring> #include <vecto ...
- luogu P1586 四方定理(背包)
题意 题解 首先吐槽一下体面的第一句话.反正我不知道(可能是因为我太菜了) 可能没有睡醒,没看出来是个背包. 但告诉是个背包了应该就好做了. #include<iostream> #inc ...
- java zyUpload 实现多文件上传
1.html部分 <form enctype="multipart/form-data"> <label>请选择文件</label> <i ...
- 学习爬虫:《Python网络数据采集》中英文PDF+代码
适合爬虫入门的书籍<Python网络数据采集>,采用简洁强大的Python语言,介绍了网络数据采集,并为采集新式网络中的各种数据类型提供了全面的指导.第一部分重点介绍网络数据采集的基本原理 ...