caffe学习笔记6:命令行,Python和Matlab接口

caffe学习笔记6:命令行,Python和Matlab接口

原网页:http://caffe.berkeleyvision.org/tutorial/interfaces.html

主要内容

caffe的底层是C++源码,有三种接口供日常使用分别是: command line ,python ,matlab.他们的接口分别被称为cmdcaffe,pycaffe ,matcaffe


1、Command Line 命令行使用caffe

命令行接口可以对caffe模型进行训练,评分和诊断。
Run caffe without any arguments for help. 直接输入caffe for help
This tool and others are found in caffe/build/tools.
一下的例子需要先编译Lenet/MNIST

1.1、Training:

Train 进行学习,回复模型,进行fine-turn
1、所有的训练都需要 -solver solver.prototxt 这个参数传入solver配置
2、继续原来的训练需要-snapshot model_iter_1000.solverstate 参数传入一个 solver snapshot.
3、fine-turn原有的模型 -weights model.caffemodel 需要传入这个参数供模型初始化
For example, you can run:

# 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-turn过程查看 examples/finetuning_on_flickr_style, 按照如下方法调用

# 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

1.2、Testing:

caffe 的test通过在测试阶段评估模型,报告网络的输出作为网络的得分。
网络结构必须被定义好输出一个准确度或者是网络的loss,每一个batch的分数会被报道最后总的平均分数会被报道。

# 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

1.3、Benchmarking

caffe time benchmarks model execution layer-by-layer through timing and synchronization。
逐层检测运行时间?
可以帮助我们更好的修改网络

# (These example calls require you complete the LeNet / MNIST example first.)
# time LeNet training on CPU for 10 iterations
caffe time -model examples/mnist/lenet_train_test.prototxt -iterations 10
# time LeNet training on GPU for the default 50 iterations
caffe time -model examples/mnist/lenet_train_test.prototxt -gpu 0
# 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

1.4、Diagnostics: 诊断

caffe device_query reports GPU details for reference and checking device ordinals for running on a given device in multi-GPU machines.
报告GPU的细节以供参考,并检测设备序列号以供多GPU时使用

# query the first device
caffe device_query -gpu 0

1.5、Parallelism: 多GPU同时训练

the -gpu flag to the caffe tool can take a comma separated list of IDs to run on multiple GPUs. A solver and net will be instantiated for each GPU so the batch size is effectively multiplied by the number of GPUs. To reproduce single GPU training, reduce the batch size in the network definition accordingly.

# train on GPUs 0 & 1 (doubling the batch size)
caffe train -solver examples/mnist/lenet_solver.prototxt -gpu 0,1
# train on all GPUs (multiplying batch size by number of devices)
caffe train -solver examples/mnist/lenet_solver.prototxt -gpu all

2、Python

python接口pycaffe,是caffe模型,在caffe/python中。

通过import caffe来导入模型,前向和反向处理,处理IO,可视化网络,甚至是指导solving。

所有模型的数据,派生物,参数都可以阅读和写入。

1、caffe.Net is the central interface for loading, configuring, and running models.
2、 caffe.Classifier and c**affe.Detector** provide convenience interfaces for common tasks.
2、caffe.SGDSolver exposes the solving interface.
3、caffe.io handles input / output with preprocessing and protocol buffers.
4、caffe.draw visualizes network architectures.
5、Caffe blobs are exposed as numpy ndarrays for ease-of-use and efficiency.

Tutorial IPython notebooks are found in caffe/examples: do ipython notebook caffe/examples to try them. For developer reference docstrings can be found throughout the code.

Compile pycaffe by make pycaffe. Add the module directory to your PYTHONPATHbyexportPYTHONPATH=/path/to/caffe/python: P Y T H O N P A T H b y e x p o r t P Y T H O N P A T H = / p a t h / t o / c a f f e / p y t h o n : PYTHONPATH or the like for import caffe.

3、Use MatCaffe 使用matlab 没有看

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值