caffe学习(四)caffe的接口参数说明

caffe接口参数

C接口

train相关参数

  • -solver参数(必须有),与solver.prototxt文件一起使用
  • -snapshot参数(可选),通常用来从之前训练一半的模型xxx.solverstate继续训练使用
  • -weights参数(选填),与训练好的model.caffemodel一起使用,用来在fine-tuning的时候初始化参数
  • -gpu参数,用来选择使用GPU,根据nvidia-smi的GPU的ID选择,比如选择第三块GPU就使用-gpu 2的参数,如果想使用所有的GPU一起跑一个程序,就使用-gpu all

举个例子

# train LeNet
caffe train -solver examples/mnist/lenet_solver.prototxt
# train on GPU 2
caffe train -solver examples/mnist/lenet_solver.prototxt -gpu 2
# resume training from the half-way point snapshot
caffe train -solver examples/mnist/lenet_solver.prototxt -snapshot examples/mnist/lenet_iter_5000.solverstate
# fine-tune CaffeNet model weights for style recognition
caffe train -solver examples/finetuning_on_flickr_style/solver.prototxt -weights models/bvlc_reference_caffenet/bvlc_reference_caffenet.caffemodel

test、time相关参数

  • -iterations迭代次数,time的时候测试的次数,默认为50次
  • -model测试时候选择加载的模型,对应train_val.prototxt或者deploy.prototxt一起使用

举个例子

# score the learned LeNet model on the validation set as defined in the
# model architeture lenet_train_test.prototxt
caffe test -model examples/mnist/lenet_train_test.prototxt -weights examples/mnist/lenet_iter_10000.caffemodel -gpu 0 -iterations 100
# time a model architecture with the given weights on the first GPU for 10 iterations
caffe time -model examples/mnist/lenet_train_test.prototxt -weights examples/mnist/lenet_iter_10000.caffemodel -gpu 0 -iterations 10

device_query相关参数

这个模块用来查看多GPU时候的一些显卡相关信息。举例

# query the first device
caffe device_query -gpu 0

python接口

通过import caffe来加载caffe模块,几个比较重要的模块caffe.Net, caffe.SDGSolver, caffe.io, caffe.draw