wjmishuai / blog_20160315_1_342838

来自CSDN博客:深度学习与人脸识别系列(4)__利用caffe训练深度学习模型 http://blog.csdn.net/wjmishuai/article/details/50854162#

  Ubuntu 图片 实现原理和过程 深度学习 脸部识别 最后更新时间 2016-03-15 17:49:46
blog_20160315_1_342838 38行 Text
Raw
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
#!/bin/bash


#-----------------------------------------------------------------------------------------


#生成训练集和验证集
#made by 郭开


#-----------------------------------------------------------------------------------------


#保存图片的路径  
PATH=/media/gk/9ec75485-26b1-471f-9b7b-d18554ca3fdd/aa
echo "start..."
#遍历文件夹
for name in $PATH/webface_img/*;do
        var=0
#遍历文件夹中的图片
        for file_name in $name/*;do  
            var=$(($var+1));  
            str=$file_name  
            #保存图片路径
            str=${str#*img}  
            #保存图片lable  
            lable=${str#*/}  
            lable=${lable%%/*}  
            if [ "$var" = "1" ] || [ "$var" = "3" ] || [ "$var" = "5" ]; then  
            #验证集  
            echo $str" "$lable>>/home/gk/val.txt  
            else  
            #测试集  
            echo $str" "$lable>>/home/gk/train.txt  
            fi  
done  
done  
echo "Done."
blog_20160315_2_3802420 78行 Text
Raw
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
#!/usr/bin/env sh  


#-----------------------------------------------------------------------------------------  
  
  
# 将图片批量生成lmbd格式的数据存储
#made by 郭开  
  
  
#-----------------------------------------------------------------------------------------  
  
#保存生成的lmdb的目录  
EXAMPLE=/media/gk/9ec75485-26b1-471f-9b7b-d18554ca3fdd/aa/lmdb_webface
  
#train.txt和val.txt所在的目录
DATA=/home/gk
  
#转换图片的工具所在的目录  
TOOLS=/home/gk/caffe-master/build/tools  
  
#图片所在的目录
TRAIN_DATA_ROOT=/media/gk/9ec75485-26b1-471f-9b7b-d18554ca3fdd/aa/webface_img

VAL_DATA_ROOT=/media/gk/9ec75485-26b1-471f-9b7b-d18554ca3fdd/aa/webface_img
  
# 设置 RESIZE=true 可以把图片resize成想要的尺寸。
RESIZE=true
if $RESIZE; then
  RESIZE_HEIGHT=227
  RESIZE_WIDTH=227
else
  RESIZE_HEIGHT=0
  RESIZE_WIDTH=0
fi


if [ ! -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 1
fi


if [ ! -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 1
fi


echo "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/train_lmdb


echo "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/val_lmdb


echo "Done."
blog_20160315_3_8927613 22行 Text
Raw
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
#!/usr/bin/env sh  


#-----------------------------------------------------------------------------------------    
    
    
# 计算图像均值
#made by 郭开    
    
    
#-----------------------------------------------------------------------------------------    
#lmdb格式的文件所在的路径
EXAMPLE=/media/gk/9ec75485-26b1-471f-9b7b-d18554ca3fdd/aa/lmdb_webface
#均值文件保存的路径
DATA=/media/gk/44CA719BCA718A46  
#转换图片的工具所在的目录 
TOOLS=/home/gk/caffe-master/build/tools  
  
$TOOLS/compute_image_mean $EXAMPLE/train_lmdb \  
  $DATA/mean.binaryproto  
  
echo "Done."  
blog_20160315_4_2657368 18行 Text
Raw
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
net: "/home/gk/caffe-master/examples/vgg/train.prototxt"
test_iter: 100
test_interval: 1000


base_lr: 0.001
lr_policy: "step"
gamma: 0.95
stepsize:  100000
momentum: 0.9
weight_decay: 0.0005
display: 100
max_iter:  5000000
snapshot:  50000
snapshot_prefix: "/home/gk/caffe-master/examples/DeepID/snapshot"
solver_mode: GPU
device_id:0
#debug_info: true
blog_20160315_5_4435274 298行 Text
Raw
   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
name: "VGG_FACE_16_layers"
layer {
  top: "data_1"
  top: "label_1"
  name: "data_1"
  type: "Data"
  data_param {
    source: "/media/gk/9ec75485-26b1-471f-9b7b-d18554ca3fdd/aa/webface_lmdb/train"
    backend:LMDB
    batch_size: 128
  }
  transform_param {
     mean_file: "/media/gk/9ec75485-26b1-471f-9b7b-d18554ca3fdd/aa/webface_lmdb/mean.binaryproto"
     mirror: true
  }
  include: { phase: TRAIN }
}


layer {
  top: "data_1"
  top: "label_1"
  name: "data_1"
  type: "Data"
  data_param {
    source: "/media/gk/9ec75485-26b1-471f-9b7b-d18554ca3fdd/aa/webface_lmdb/val"
    backend:LMDB
    batch_size: 128
  }
  transform_param {
    mean_file: "/media/gk/9ec75485-26b1-471f-9b7b-d18554ca3fdd/aa/webface_lmdb/mean.binaryproto"
    mirror: true
  }
  include: { 
    phase: TEST 
  }
}


layers {
  bottom: "data"
  top: "conv1_1"
  name: "conv1_1"
  type: CONVOLUTION
  convolution_param {
    num_output: 64
    pad: 1
    kernel_size: 3
  }
}
layers {
  bottom: "conv1_1"
  top: "conv1_1"
  name: "relu1_1"
  type: RELU
}
layers {
  bottom: "conv1_1"
  top: "conv1_2"
  name: "conv1_2"
  type: CONVOLUTION
  convolution_param {
    num_output: 64
    pad: 1
    kernel_size: 3
  }
}
layers {
  bottom: "conv1_2"
  top: "conv1_2"
  name: "relu1_2"
  type: RELU
}
layers {
  bottom: "conv1_2"
  top: "pool1"
  name: "pool1"
  type: POOLING
  pooling_param {
    pool: MAX
    kernel_size: 2
    stride: 2
  }
}
layers {
  bottom: "pool1"
  top: "conv2_1"
  name: "conv2_1"
  type: CONVOLUTION
  convolution_param {
    num_output: 128
    pad: 1
    kernel_size: 3
  }
}
layers {
  bottom: "conv2_1"
  top: "conv2_1"
  name: "relu2_1"
  type: RELU
}
layers {
  bottom: "conv2_1"
  top: "conv2_2"
  name: "conv2_2"
  type: CONVOLUTION
  convolution_param {
    num_output: 128
    pad: 1
    kernel_size: 3
  }
}
layers {
  bottom: "conv2_2"
  top: "conv2_2"
  name: "relu2_2"
  type: RELU
}
layers {
  bottom: "conv2_2"
  top: "pool2"
  name: "pool2"
  type: POOLING
  pooling_param {
    pool: MAX
    kernel_size: 2
    stride: 2
  }
}
layers {
  bottom: "pool2"
  top: "conv3_1"
  name: "conv3_1"
  type: CONVOLUTION
  convolution_param {
    num_output: 256
    pad: 1
    kernel_size: 3
  }
}
layers {
  bottom: "conv3_1"
  top: "conv3_1"
  name: "relu3_1"
  type: RELU
}
layers {
  bottom: "conv3_1"
  top: "conv3_2"
  name: "conv3_2"
  type: CONVOLUTION
  convolution_param {
    num_output: 256
    pad: 1
    kernel_size: 3
  }
}
layers {
  bottom: "conv3_2"
  top: "conv3_2"
  name: "relu3_2"
  type: RELU
}
layers {
  bottom: "conv3_2"
  top: "conv3_3"
  name: "conv3_3"
  type: CONVOLUTION
  convolution_param {
    num_output: 256
    pad: 1
    kernel_size: 3
  }
}
layers {
  bottom: "conv3_3"
  top: "conv3_3"
  name: "relu3_3"
  type: RELU
}
layers {
  bottom: "conv3_3"
  top: "pool3"
  name: "pool3"
  type: POOLING
  pooling_param {
    pool: MAX
    kernel_size: 2
    stride: 2
  }
}
layers {
  bottom: "pool3"
  top: "conv4_1"
  name: "conv4_1"
  type: CONVOLUTION
  convolution_param {
    num_output: 512
    pad: 1
    kernel_size: 3
  }
}
layers {
  bottom: "conv4_1"
  top: "conv4_1"
  name: "relu4_1"
  type: RELU
}
layers {
  bottom: "conv4_1"
  top: "conv4_2"
  name: "conv4_2"
  type: CONVOLUTION
  convolution_param {
    num_output: 512
    pad: 1
    kernel_size: 3
  }
}
layers {
  bottom: "conv4_2"
  top: "conv4_2"
  name: "relu4_2"
  type: RELU
}
layers {
  bottom: "conv4_2"
  top: "conv4_3"
  name: "conv4_3"
  type: CONVOLUTION
  convolution_param {
    num_output: 512
    pad: 1
    kernel_size: 3
  }
}
layers {
  bottom: "conv4_3"
  top: "conv4_3"
  name: "relu4_3"
  type: RELU
}
layers {
  bottom: "conv4_3"
  top: "pool4"
  name: "pool4"
  type: POOLING
  pooling_param {
    pool: MAX
    kernel_size: 2
    stride: 2
  }
}
layers {
  bottom: "pool4"
  top: "conv5_1"
  name: "conv5_1"
  type: CONVOLUTION
  convolution_param {
    num_output: 512
    pad: 1
    kernel_size: 3
  }
}
layers {
  bottom: "conv5_1"
  top: "conv5_1"
  name: "relu5_1"
  type: RELU
}
layers {
  bottom: "conv5_1"
  top: "conv5_2"
  name: "conv5_2"
  type: CONVOLUTION
  convolution_param {
    num_output: 512
    pad: 1
    kernel_size: 3
  }
}
layers {
  bottom: "conv5_2"
  top: "conv5_2"
  name: "relu5_2"
  type: RELU
}
layers {
  bottom: "conv5_2"
  top: "conv5_3"
  name: "conv5_3"
  type: CONVOLUTION
  convolution_param {
    num_output: 512
    pad: 1
    kernel_size: 3
  }
}