最近参考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. 关于直播学习笔记-002-Red5 & Sewise Player & Wirecast

    一.工具软件 [1]. 视频采集端 Red5 Demo:http://192.168.31.107:5080/demos/simpleBroadcaster.html Telestream:Wirec ...

  2. ionic调用数据接口(post、解决 payload 问题)

    $http({method:'POST', url:apiUrl, headers:{'Content-Type': 'application/x-www-form-urlencoded; chars ...

  3. Receiver type for instance message is a forward

    本文转载至 http://my.oschina.net/sunqichao/blog?disp=2&catalog=0&sort=time&p=3 这往往是引用的问题.ARC要 ...

  4. c++11 数值类型和字符串的相互转换

    string和数值类型转换 c++11提供了to_string方法,可以方便的将各种数值类型转换为 字符串类型: std::string to_string(int value); std::stri ...

  5. 【Java nio】java nio笔记

    缓冲区操作:缓冲区,以及缓冲区如何工作,是所有I/O的基础.所谓“输入/输出”讲的无非就是把数据移出货移进缓冲区.进程执行I/O操作,归纳起来也就是向操作系统发出请求,让它要么把缓冲区里的数据排干,要 ...

  6. JS-随机div颜色

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  7. salt-stack更换主机名

    author:headsen  chen date: 2018-09-30  11:22:40 1,建立master端和client端的正常连接 #master yum -y install epel ...

  8. SpringMVC实现简单应用

    我们都知道,servlet代码一般来说只能在一个servlet中做判断去实现一个servlet响应多个请求, 但是springMVC的话还是比较方便的,主要有两种方式去实现一个controller里能 ...

  9. 110道python题+理解(不断更新)

    此篇题目在网上已经广为流传,但好多都不做解释,所以我想着自己一道一道的做一遍,并将相关涉及的做个补充,个人知识毕竟片面,有不足的地方还请大家多多指正 一.请用一行代码实现1-100之和 >> ...

  10. 【JavaScript算法】---希尔排序

    一.什么是希尔排序 希尔排序(Shell's Sort)是插入排序的一种又称“缩小增量排序”,是直接插入排序算法的一种更高效的改进版本.   思路:      希尔排序是把记录按下标的一定增量分组,对 ...