【caffe】googlenet在windows下训练以及遇到的一系列问题——【caffe学习四】

来源:互联网 发布:linux的保存命令 编辑:程序博客网 时间:2024/05/18 03:01

大部分步骤可以参考上篇:http://blog.csdn.net/qq_15947787/article/details/78428478

本文在上篇的基础上进行说明,上篇是分5类,本文分4类


步骤1-4同上篇。

5.修改create_imagenet.sh内容:

与上篇不同的是RESIZE_HEIGHT与RESIZE_WIDTH修改为224

#!/usr/bin/env sh# Create the imagenet lmdb inputs# N.B. set the path to the imagenet train + val data dirsset -eEXAMPLE=dataDATA=dataTOOLS=toolsTRAIN_DATA_ROOT=data/train/VAL_DATA_ROOT=data/val/# Set RESIZE=true to resize the images to 256x256. Leave as false if images have# already been resized using another tool.RESIZE=trueif $RESIZE; then  RESIZE_HEIGHT=224  RESIZE_WIDTH=224else  RESIZE_HEIGHT=0  RESIZE_WIDTH=0fiif [ ! -d "$TRAIN_DATA_ROOT" ]; then  echo "Error: TRAIN_DATA_ROOT is not a path to a directory: $TRAIN_DATA_ROOT"  echo "Set the TRAIN_DATA_ROOT variable in create_imagenet.sh to the path" \       "where the ImageNet training data is stored."  exit 1fiif [ ! -d "$VAL_DATA_ROOT" ]; then  echo "Error: VAL_DATA_ROOT is not a path to a directory: $VAL_DATA_ROOT"  echo "Set the VAL_DATA_ROOT variable in create_imagenet.sh to the path" \       "where the ImageNet validation data is stored."  exit 1fiecho "Creating train lmdb..."GLOG_logtostderr=1 $TOOLS/convert_imageset \    --resize_height=$RESIZE_HEIGHT \    --resize_width=$RESIZE_WIDTH \    --shuffle \    $TRAIN_DATA_ROOT \    $DATA/train.txt \    $EXAMPLE/img_train_lmdbecho "Creating val lmdb..."GLOG_logtostderr=1 $TOOLS/convert_imageset \    --resize_height=$RESIZE_HEIGHT \    --resize_width=$RESIZE_WIDTH \    --shuffle \    $VAL_DATA_ROOT \    $DATA/val.txt \    $EXAMPLE/img_val_lmdbecho "Done."read


步骤6-8同上篇。

9.修改D:\caffe-train\models\bvlc_reference_caffenet下

solver.prototxt内容:

修改位置:

net路径

snapshot_prefix路径

net: "D:/caffe-train/models/bvlc_googlenet/train_val.prototxt"test_iter: 9test_interval: 100test_initialization: falsedisplay: 40average_loss: 40base_lr: 0.01lr_policy: "step"stepsize: 320gamma: 0.96max_iter: 10000momentum: 0.9weight_decay: 0.0002snapshot: 100snapshot_prefix: "D:/caffe-train/models/bvlc_googlenet"solver_mode: GPU

deploy.prototxt内容:

修改位置:

loss3/classifier层的num_output为分类数(一处)

layer {  name: "loss3/classifier"  type: "InnerProduct"  bottom: "pool5/7x7_s1"  top: "loss3/classifier"  param {    lr_mult: 1    decay_mult: 1  }  param {    lr_mult: 2    decay_mult: 0  }  inner_product_param {    num_output: 4  #改成你的数据集类别数    weight_filler {      type: "xavier"    }    bias_filler {      type: "constant"      value: 0    }  }}


train_val.prototxt内容:

修改位置:

注释mean_value三行值,增加mean_file:路径(两处)

修改train和val的source路径(两处)

修改batch_size大小(两处)

修改输出loss1/classifier层,loss2/classifier层,loss3/classifier层的num_output为分类数(三处)

name: "GoogleNet"layer {  name: "data"  type: "Data"  top: "data"  top: "label"  include {    phase: TRAIN  }  transform_param {    mirror: true    crop_size: 224mean_file: "D:/caffe-train/data/imagenet_mean.binaryproto"    #mean_value: 104    #mean_value: 117    #mean_value: 123  }  data_param {    source: "D:/caffe-train/data/img_train_lmdb"    batch_size: 8    backend: LMDB  }}layer {  name: "data"  type: "Data"  top: "data"  top: "label"  include {    phase: TEST  }  transform_param {    mirror: false    crop_size: 224mean_file: "D:/caffe-train/data/imagenet_mean.binaryproto"    #mean_value: 104    #mean_value: 117    #mean_value: 123  }  data_param {    source: "D:/caffe-train/data/img_val_lmdb"    batch_size: 50 #和solver中的test_iter相乘约等于验证集大小      backend: LMDB  }}


layer {  name: "loss1/classifier"  type: "InnerProduct"  bottom: "loss1/fc"  top: "loss1/classifier"  param {    lr_mult: 1    decay_mult: 1  }  param {    lr_mult: 2    decay_mult: 0  }  inner_product_param {    num_output: 4  #改成你的数据集类别数    weight_filler {      type: "xavier"    }    bias_filler {      type: "constant"      value: 0    }  }}

layer {  name: "loss2/classifier"  type: "InnerProduct"  bottom: "loss2/fc"  top: "loss2/classifier"  param {    lr_mult: 1    decay_mult: 1  }  param {    lr_mult: 2    decay_mult: 0  }  inner_product_param {    num_output: 4 #改成你的数据集类别数    weight_filler {      type: "xavier"    }    bias_filler {      type: "constant"      value: 0    }  }}

layer {  name: "loss3/classifier"  type: "InnerProduct"  bottom: "pool5/7x7_s1"  top: "loss3/classifier"  param {    lr_mult: 1    decay_mult: 1  }  param {    lr_mult: 2    decay_mult: 0  }  inner_product_param {    num_output: 4 #改成你的数据集类别数     weight_filler {      type: "xavier"    }    bias_filler {      type: "constant"      value: 0    }  }}

10.修改train_caffenet.bat内容:

tools\caffe.exe train --solver=D:\caffe-train\models\bvlc_googlenet\solver.prototxtpause


11.运行train_caffenet.bat


训练完成后,在D:\caffe-train\models下生成models。


—————————————————————————————————————————

问题1:top_k must be less than or equal to the number of classes

解决方法:由于我现在分的是4类,修改train_val.prototxt中top_k值为4,原值为5,有三处需要修改


—————————————————————————————————————————

问题2:Check failed: error == cudaSuccess (2 vs. 0)  out of memory

解决方法:适当减小train_val.prototxt中batch_size大小














阅读全文
0 0