Notes for caffe (1) 命令参数和使用方法

本文详细介绍了Caffe训练工具的使用方法,包括从头训练和继续训练两种方式,并提供了具体的命令示例。此外还介绍了其他工具如图片转换、计算均值及特征提取等,以及整个训练流程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

尽管caffe还是通过python接口方便调试,这里也首先记录C++接口(其实是命令行模式)下如何使用caffe训练工具。

1. 训练工具

编译之后的可执行文件位于 build/tools/caffe,其使用参数的查看方法:

$./build/tools/caffe --help
commands:
  train           train or finetune a model
  test            score a model
  device_query    show GPU diagnostic information
  time            benchmark model execution time

……
  Flags from /home/zsh/zsh_dl_code/caffe-master/tools/caffe.cpp:
    -gpu (Optional; run in GPU mode on given device IDs separated by ','.Use
      '-gpu all' to run on all available GPUs. The effective training batch
      size is multiplied by the number of devices.) type: string default: ""
    -iterations (The number of iterations to run.) type: int32 default: 50
    -level (Optional; network level.) type: int32 default: 0
    -model (The model definition protocol buffer text file.) type: string
      default: ""
    -phase (Optional; network phase (TRAIN or TEST). Only used for 'time'.)
      type: string default: ""
    -sighup_effect (Optional; action to take when a SIGHUP signal is received:
      snapshot, stop or none.) type: string default: "snapshot"
    -sigint_effect (Optional; action to take when a SIGINT signal is received:
      snapshot, stop or none.) type: string default: "stop"
    -snapshot (Optional; the snapshot solver state to resume training.)
      type: string default: ""
    -solver (The solver definition protocol buffer text file.) type: string
      default: ""
    -stage (Optional; network stages (not to be confused with phase), separated
      by ','.) type: string default: ""
    -weights (Optional; the pretrained weights to initialize finetuning,
      separated by ','. Cannot be set simultaneously with snapshot.)
      type: string default: ""
……

可以看见详细的参数列表,常用的方法有两种:一种是从头开始训练,参见examples/mnist/train_lenet.sh

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

一种是继续训练已有的模型,如:

./build/tools/caffe train
    -solver=examples/finetune_pascal_detection/pascal_finetune_solver.prototxt
    -weights=$PRETRAINED_CAFFEMODEL$

2. 其他工具

(1) convert_imageset 将图片resize为给定大小,参见examples/imagenet/create_imagenet.sh

$TOOLS/convert_imageset
    --resize_height=$RESIZE_HEIGHT
    --resize_width=$RESIZE_WIDTH
    --shuffle
    $TRAIN_DATA_ROOT
    $DATA/train.txt
    $EXAMPLE/ilsvrc12_train_lmdb

(2) compute_image_mean 计算训练集均值并存储为二进制文件,参见 examples/imagenet/make_imagenet_mean.sh

$TOOLS/compute_image_mean $EXAMPLE/ilsvrc12_train_lmdb $DATA/imagenet_mean.binaryproto

(3) extract_features 提取特征,注释说明了它的用法(注意:可以一次性对多个数据集进行特征提取):

extract_features  
    pretrained_net_param  feature_extraction_proto_file
    extract_feature_blob_name1[,name2,...]  
    save_feature_dataset_name1[,name2,...]  
    num_mini_batches  
    db_type  
    [CPU/GPU] [DEVICE_ID=0]

例如:

$TOOLS/extract_features
    models/bvlc_reference_caffenet/bvlc_reference_caffenet.caffemodel
    examples/feature_extraction/imagenet_val.prototxt
    fc7 
    examples/feature_extraction/features 
    10 
    leveldb

3. 流程

第一步,将图片库转化为leveldb/lmdb格式的数据库,这个过程包含了图片resize;
第二步,计算均值并存储;
第三步,准备好网络参数文件:train_test.prototxt,deploy.prototxt;
第四步,训练,可视化,测试。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

张似衡

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值