最近参考http://blog.csdn.net/hlx371240/article/details/51388022一文,用LFW数据集对vgg_face.caffemodel进行fine-tune。主要步骤和http://blog.csdn.net/hlx371240/article/details/51388022文中所阐述的步骤没有区别。个别地方稍微补充一下:

1.LFW标定生成程序

#include <stdio.h>
#include <unistd.h>
#include <dirent.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <string.h>
#include <assert.h> #define MAX_PATH_LEN 512 int count =;
char dirPath[MAX_PATH_LEN]; void listAllFiles(char *dirname)
{
assert(dirname != NULL); char path[];
struct dirent *filename;
DIR *dir; dir = opendir(dirname);
if(dir == NULL)
{
printf("open dir %s error!\n",dirname);
exit();
} while((filename = readdir(dir)) != NULL)
{
if(!strcmp(filename->d_name,".")||!strcmp(filename->d_name,".."))
continue; sprintf(path,"%s/%s",dirname,filename->d_name); struct stat s;
lstat(path,&s); if(S_ISDIR(s.st_mode))
{
listAllFiles(path);
count++; //每个子文件夹对应的labelID计算
}
else
{
printf("%s/%s %d\n",dirname,filename->d_name,count);
}
}
closedir(dir);
} int main(int argc, char **argv)
{
if(argc != )
{
printf("one dir required!(for eample: ./a.out /home/myFolder)\n");
exit();
}
strcpy(dirPath,argv[]);
listAllFiles(dirPath);
//printf("total files:%d\n",count);
return ;
}

程序使用命令:

gcc label_generate.c -o label_generate
./label_generate  $DATA_ROOT/lfw

2. Finetuning的prototxt

我们只针对fc8进行fine-tune,因此将相应的层名称修改为fc8_finetune

# Data Layer
layers {
name: "data"
type: DATA
include {
phase: TRAIN
}
transform_param {
crop_size:
mean_file: "/$DATA_ROOT/face_mean.binaryproto"
mirror: true
}
data_param {
source: "/$DATA_ROOT/face_train_lmdb"
batch_size:
backend: LMDB
}
top: "data"
top: "label"
}
layers {
name: "data"
type: DATA
include {
phase: TEST
}
transform_param {
crop_size:
mean_file: "/$DATA_ROOT/face_mean.binaryproto"
mirror: false
}
data_param {
source: "$DATA_ROOT/face_val_lmdb"
batch_size:
backend: LMDB
}
top: "data"
top: "label"
}
# conv1_1~fc7
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:
pad:
kernel_size:
}
}
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:
stride:
}
}
layers {
bottom: "pool1"
top: "conv2_1"
name: "conv2_1"
type: CONVOLUTION
convolution_param {
num_output:
pad:
kernel_size:
}
}
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:
pad:
kernel_size:
}
}
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:
stride:
}
}
layers {
bottom: "pool2"
top: "conv3_1"
name: "conv3_1"
type: CONVOLUTION
convolution_param {
num_output:
pad:
kernel_size:
}
}
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:
pad:
kernel_size:
}
}
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:
pad:
kernel_size:
}
}
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:
stride:
}
}
layers {
bottom: "pool3"
top: "conv4_1"
name: "conv4_1"
type: CONVOLUTION
convolution_param {
num_output:
pad:
kernel_size:
}
}
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:
pad:
kernel_size:
}
}
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:
pad:
kernel_size:
}
}
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:
stride:
}
}
layers {
bottom: "pool4"
top: "conv5_1"
name: "conv5_1"
type: CONVOLUTION
convolution_param {
num_output:
pad:
kernel_size:
}
}
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:
pad:
kernel_size:
}
}
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:
pad:
kernel_size:
}
}
layers {
bottom: "conv5_3"
top: "conv5_3"
name: "relu5_3"
type: RELU
}
layers {
bottom: "conv5_3"
top: "pool5"
name: "pool5"
type: POOLING
pooling_param {
pool: MAX
kernel_size:
stride:
}
}
layers {
bottom: "pool5"
top: "fc6"
name: "fc6"
type: INNER_PRODUCT
inner_product_param {
num_output:
}
}
layers {
bottom: "fc6"
top: "fc6"
name: "relu6"
type: RELU
}
layers {
bottom: "fc6"
top: "fc6"
name: "drop6"
type: DROPOUT
dropout_param {
dropout_ratio: 0.5
}
}
layers {
bottom: "fc6"
top: "fc7"
name: "fc7"
type: INNER_PRODUCT
inner_product_param {
num_output:
}
}
layers {
bottom: "fc7"
top: "fc7"
name: "relu7"
type: RELU
}
layers {
bottom: "fc7"
top: "fc7"
name: "drop7"
type: DROPOUT
dropout_param {
dropout_ratio: 0.5
}
}
# fc8_finetune and Loss
layers {
bottom: "fc7"
top: "fc8"
name: "fc8_finetune"
type: INNER_PRODUCT
inner_product_param {
num_output:
}
}
layers {
name: "loss"
bottom: "fc8"
bottom: "label"
top: "loss"
type: SOFTMAX_LOSS
}

3.脚本配置

crete_lmdb.sh:生成训练和测试数据

#!/usr/bin/env sh
# Create the imagenet lmdb inputs
# N.B. set the path to the imagenet train + val data dirs # CAFFE_ROOT is the path of your caffe and you should set it as the absolute path
# train.txt and val.txt are saved in the path $CAFFE_ROOT/VGG/data
EXAMPLE=$CAFFE_ROOT/VGG/lmdb_root
DATA=$CAFFE_ROOT/VGG/data
TOOLS=$CAFFE_ROOT/build/tools TRAIN_DATA_ROOT=$CAFFE_ROOT/VGG/data
VAL_DATA_ROOT=$CAFFE_ROOT/VGG/data # Set RESIZE=true to resize the images to 256x256. Leave as false if images have
# already been resized using another tool.
RESIZE=true
if $RESIZE; then
RESIZE_HEIGHT=
RESIZE_WIDTH=
else
RESIZE_HEIGHT=
RESIZE_WIDTH=
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
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
fi echo "Creating train lmdb..." GLOG_logtostderr= $TOOLS/convert_imageset.bin \
--resize_height=$RESIZE_HEIGHT \
--resize_width=$RESIZE_WIDTH \
--shuffle \
$TRAIN_DATA_ROOT \
$DATA/train.txt \
$EXAMPLE/face_train_lmdb echo "Creating val lmdb..." GLOG_logtostderr= $TOOLS/convert_imageset.bin \
--resize_height=$RESIZE_HEIGHT \
--resize_width=$RESIZE_WIDTH \
--shuffle \
$VAL_DATA_ROOT \
$DATA/val.txt \
$EXAMPLE/face_val_lmdb echo "Done."

compute_mean.sh:生成face_mean.binaryproto

#!/usr/bin/env sh
# Compute the mean image from the imagenet training lmdb
# N.B. this is available in data/ilsvrc12 EXAMPLE=$CAFFE_ROOT/VGG/lmdb_root
DATA=$CAFFE_ROOT/VGG/data
TOOLS=$CAFFE_ROOT/build/tools $TOOLS/compute_image_mean $EXAMPLE/face_train_lmdb \
$DATA/face_mean.binaryproto echo "Done."

vgg_train.sh:开启训练

#!/usr/bin/env sh

$CAFFE_ROOT/build/tools/caffe train \
--solver=$CAFFE_ROOT/VGG/solver.prototxt \
--weights=$CAFFE_ROOT/VGG/VGG_FACE.caffemodel -gpu=

vgg_face人脸识别的更多相关文章

  1. Windows caffe VGG人脸识别

    caffe自带的例子有mnist和cifar10,cifar10和mnist的运行方式类型,下好图片数据文件后,训练例子中的模型,然后测试模型,也可以自己用图片进行预测分类(自己图片最好是cifar1 ...

  2. 基于深度学习的人脸识别系统(Caffe+OpenCV+Dlib)【三】VGG网络进行特征提取

    前言 基于深度学习的人脸识别系统,一共用到了5个开源库:OpenCV(计算机视觉库).Caffe(深度学习库).Dlib(机器学习库).libfacedetection(人脸检测库).cudnn(gp ...

  3. OpenCV人脸识别Eigen算法源码分析

    1 理论基础 学习Eigen人脸识别算法需要了解一下它用到的几个理论基础,现总结如下: 1.1 协方差矩阵 首先需要了解一下公式: 共公式可以看出:均值描述的是样本集合的平均值,而标准差描述的则是样本 ...

  4. OpenCV人脸识别LBPH算法源码分析

    1 背景及理论基础 人脸识别是指将一个需要识别的人脸和人脸库中的某个人脸对应起来(类似于指纹识别),目的是完成识别功能,该术语需要和人脸检测进行区分,人脸检测是在一张图片中把人脸定位出来,完成的是搜寻 ...

  5. jQuery 人脸识别插件,支持图片和视频

    jQuery Face Detection 是一款人脸检测插件,能够检测到图片,视频和画布中的人脸坐标.它跟踪人脸并输出人脸模型的坐标位置为一个数组.我们相信,面部识别技术能够给我们的 Web 应用带 ...

  6. 主成分分析 (PCA) 与其高维度下python实现(简单人脸识别)

    Introduction 主成分分析(Principal Components Analysis)是一种对特征进行降维的方法.由于观测指标间存在相关性,将导致信息的重叠与低效,我们倾向于用少量的.尽可 ...

  7. 【Win10 应用开发】人脸识别

    可能你会认为人脸识别用起来会很复杂,老周当初也这么想,但通过实际操作后,我发现非然. 经过微软封装的东西,向来都是复杂问题简单化,只要用得舒心,代码越少越好,用最少的代码做最多的事情,此为大师境界也. ...

  8. 关于opencv中人脸识别主函数的部分注释详解。

    近段时间在搞opencv的视频人脸识别,无奈自带的分类器的准确度,实在是不怎么样,但又能怎样呢?自己又研究不清楚各大类检测算法. 正所谓,功能是由函数完成的,于是自己便看cvHaarDetectObj ...

  9. Opencv摄像头实时人脸识别

    Introduction 网上存在很多人脸识别的文章,这篇文章是我的一个作业,重在通过摄像头实时采集人脸信息,进行人脸检测和人脸识别,并将识别结果显示在左上角. 利用 OpenCV 实现一个实时的人脸 ...

随机推荐

  1. Extjs3.4--TabpanelDemo

    Ext.onReady(function () { var tab = new Ext.TabPanel({ renderTo: Ext.getBody(), height: 500 }) tab.a ...

  2. python2.0_day16_django_url_view_models_template介绍

    本节内容 Django流程介绍 Django url Django view Django models Django template Django form Django admin Django ...

  3. divmod()

    divmod() 接收两个数值,然后以元组的形式返回这两个数值的商和余数 In [1]: divmod(5, 2) Out[1]: (2, 1) In [2]: divmod(10, 7) Out[2 ...

  4. VR室内定位系统小结

    一.写在开始之前 不管是HTC 的Vive还是OC的CV1,都说明VR 定位设备和手柄都会成为未来VR的发展趋势. VR目前关键就是体验,全身心的投入,身临其境的感觉. 不能总玩着玩着,出戏了.这肯定 ...

  5. N76E003学习之路(二)

    最近一直在想N76E003和STM8M003的对比情况,在网上找了不少资料,看了不少文档,具体总结如下: STM8S003F3P6:一共20个脚,最多支持16个GPIO,支持16个外部中断:2个16位 ...

  6. 告别C#,进入了下一个阶段的学习啦

    嘿嘿,今天我们结束了C#的基础的学习,开始啦第二个阶段的学习,就是对SQL Server的学习.今天又是一个周一,又是一个新的开始,感觉我们都是一周一周的计算,而不是每天到这个点就是告别了今天的生活啦 ...

  7. windows7中的“mklink命令”

    从 Vista 以后,微软将用户文件和用户的软件配置( AppData ) 明确划分开,并且全部存放在使用者的用户目录下. Linux早已这样做了,并且在Linux中可将 home 挂载为独立分区,而 ...

  8. Jquery跨域Ajax取值

    HTML: $.ajax({ type: "get", async: false, url: "http://www.xxxxxx.com/otherLogin/chec ...

  9. java基础---->多线程之yield(三)

    yield方法的作用是放弃当前的CPU资源,将它让给其它的任务去占用CPU执行时间.但放弃的时间不确定,有可能刚刚放弃,马上又获得CPU时间片.今天我们通过实例来学习一下yield()方法的使用.最是 ...

  10. Windows 2008 server R2安装.NET Framework4时提示“灾难性故障”

    报错信息: 安装.NET Framework 4时,提示安装未成功,“灾难性故障”.服务器的操作系统是windows  server 2008 R2. 查看系统日志时显示“无法安装 Windows 更 ...