caffe (5) 命令行解析

来源:互联网 发布:最新的数据库处理技术 编辑:程序博客网 时间:2024/06/05 10:52

caffe提供三种接口:c++(命令行), python, matlab。如何使用常用的命令呢?

caffe的c++主程序caffe.cpp放在~/caffe/tools/文件夹内,在编译caffe时生成了可执行文件在~/caffe/build/tools/中,当然还有一些其它的功能文件,如:convert_imageset.cpp, train_net.cpp, test_net.cpp等也放在这个文件夹内。

caffe的命令行格式如下,

caffe <command> <args>

其中command有四种:

  • train ---- 训练或finetune模型(model),
  • test ----- 测试模型
  • device_query --- 显示gpu信息
  • time ----- 显示程序执行时

arg参数有:

  • -solver
  • -gpu
  • -snapshot
  • -weights
  • -iteration
  • -model
  • -sighup_effect
  • -sigint_effect
下面详细介绍不同参数代表的意义

(1)-solver 指定模型的配置文件,例如

./build/tools/caffe train -solver examples/mnist/lenet_solver.prototxt  

(2)-gpu 指定哪一块gpu来运行,如果是全部则是 -gpu all,例如

./build/tools/caffe train -solver examples/mnist/lenet_solver.prototxt -gpu 2

(3)-snapshot:可选参数。该参数用来从快照(snapshot)中恢复训练,例如

./build/tools/caffe train -solver examples/mnist/lenet_solver.prototxt -snapshot examples/mnist/lenet_iter_5000.solverstate

(4)-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

(5)-iterations: 可选参数,迭代次数,默认为50

(6)-model: 可选参数,定义为protocal buffer中的模型

(7)-sighup_effect:可选参数。用来设定当程序发生挂起事件时,执行的操作,可以设置为snapshot, stop或none, 默认为snapshot

(8)-sigint_effect: 可选参数。用来设定当程序发生键盘中止事件时(ctrl+c), 执行的操作,可以设置为snapshot, stop或none, 默认为stop

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

time参数显示程序运行时间

./build/tools/caffe time -model examples/mnist/lenet_train_test.prototxt -iterations 10

显示模型迭代10次所用的时间,包括forward和backward所用的时间,也包括每层forwand和backward所用的平均时间。

device_query参数用来诊断gpu信息

./build/tools/caffe device_query -gpu 0

最后,在linux下,本身就有一个time命令,因此可以结合进来使用,因此我们运行mnist例子的最终命令是(一块gpu):

sudo time ./build/toos/caffe train -solver examples/mnist/lenet_solver.prototxt


原创粉丝点击