最近参考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. python3.0与python2.0有哪些不同

    python3的语法跟python2哪里变了. 1. python3中1/2终于等于0.5 了 2. print "Hello World"变成了print("Hello ...

  2. Keil(MDK-ARM)在线调试(Ⅰ)(转)

    Ⅰ.写在前面 Keil在线调试的内容有很多,本文带来在线调试常用的内容:Debug Toolbar调试工具栏(复位.全速运行.停止运行.单步调试.逐行调试.跳出调试.运行到光标行.跳转到暂停行.调试窗 ...

  3. poj_1151 线段树

    题目大意 在平面上给定n个矩形,可以相互覆盖全部或者部分,求出矩形占据的总面积. 题目分析 将矩形按照x方向的进行分割之后,将平面沿着y方向划分一系列单元(不定高度),每个矩形在y方向上占据若干连续的 ...

  4. bootstrap+html5+css3

    一.栅格和块阴影 <!DOCTYPE html> <html> <head> <title>Bootstrap 实例 - 堆叠的水平</title ...

  5. 【黑金ZYNQ7000系列原创视频教程】01.熟悉vivado——纯逻辑led实验

    黑金论坛地址: http://www.heijin.org/forum.php?mod=viewthread&tid=36627&extra=page%3D1 爱奇艺地址: http: ...

  6. gvim编辑器_vimrc文件

    set nocompatiblesource $VIMRUNTIME/vimrc_example.vimsource $VIMRUNTIME/mswin.vimbehave mswin set dif ...

  7. 【BZOJ4282】慎二的随机数列 乱搞

    [BZOJ4282]慎二的随机数列 Description 间桐慎二是间桐家著名的废柴,有一天,他在学校随机了一组随机数列, 准备使用他那强大的人工智能求出其最长上升子序列,但是天有不测风云,人有旦夕 ...

  8. WCF(二) 使用配置文件实现WCF应用程序

    服务三要素ABCA:Address 在哪里 (包含传输方式的信息)B:Binding 怎么实现(与地址的传输方式要匹配)C:Contract做什么(服务契约) namespace WCFService ...

  9. Thrift入门之mac下的安装流程

    新建一个maven项目,先下载maven依赖  http://thrift.apache.org/download <dependency> <groupId>org.apac ...

  10. springMVC各个包下的作用

    spring的jar各包作用spring.jar是包含有完整发布的单个jar包,spring.jar中包含除了spring-mock.jar里所包含的内容外其它所有jar包的内容,因为只有在开发环境下 ...