vgg_face人脸识别
最近参考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人脸识别的更多相关文章
- Windows caffe VGG人脸识别
caffe自带的例子有mnist和cifar10,cifar10和mnist的运行方式类型,下好图片数据文件后,训练例子中的模型,然后测试模型,也可以自己用图片进行预测分类(自己图片最好是cifar1 ...
- 基于深度学习的人脸识别系统(Caffe+OpenCV+Dlib)【三】VGG网络进行特征提取
前言 基于深度学习的人脸识别系统,一共用到了5个开源库:OpenCV(计算机视觉库).Caffe(深度学习库).Dlib(机器学习库).libfacedetection(人脸检测库).cudnn(gp ...
- OpenCV人脸识别Eigen算法源码分析
1 理论基础 学习Eigen人脸识别算法需要了解一下它用到的几个理论基础,现总结如下: 1.1 协方差矩阵 首先需要了解一下公式: 共公式可以看出:均值描述的是样本集合的平均值,而标准差描述的则是样本 ...
- OpenCV人脸识别LBPH算法源码分析
1 背景及理论基础 人脸识别是指将一个需要识别的人脸和人脸库中的某个人脸对应起来(类似于指纹识别),目的是完成识别功能,该术语需要和人脸检测进行区分,人脸检测是在一张图片中把人脸定位出来,完成的是搜寻 ...
- jQuery 人脸识别插件,支持图片和视频
jQuery Face Detection 是一款人脸检测插件,能够检测到图片,视频和画布中的人脸坐标.它跟踪人脸并输出人脸模型的坐标位置为一个数组.我们相信,面部识别技术能够给我们的 Web 应用带 ...
- 主成分分析 (PCA) 与其高维度下python实现(简单人脸识别)
Introduction 主成分分析(Principal Components Analysis)是一种对特征进行降维的方法.由于观测指标间存在相关性,将导致信息的重叠与低效,我们倾向于用少量的.尽可 ...
- 【Win10 应用开发】人脸识别
可能你会认为人脸识别用起来会很复杂,老周当初也这么想,但通过实际操作后,我发现非然. 经过微软封装的东西,向来都是复杂问题简单化,只要用得舒心,代码越少越好,用最少的代码做最多的事情,此为大师境界也. ...
- 关于opencv中人脸识别主函数的部分注释详解。
近段时间在搞opencv的视频人脸识别,无奈自带的分类器的准确度,实在是不怎么样,但又能怎样呢?自己又研究不清楚各大类检测算法. 正所谓,功能是由函数完成的,于是自己便看cvHaarDetectObj ...
- Opencv摄像头实时人脸识别
Introduction 网上存在很多人脸识别的文章,这篇文章是我的一个作业,重在通过摄像头实时采集人脸信息,进行人脸检测和人脸识别,并将识别结果显示在左上角. 利用 OpenCV 实现一个实时的人脸 ...
随机推荐
- Mac下,如何把项目托管到Github上(Github Desktop的使用)
在上一篇中,详细讲解了使用X-code和终端配合上传代码的方法,这种方法比较传统,中间会有坑,英文看起来也费劲,不过Github官方提供了一个Mac版的客户端,如下图:
- PHP-005
MySql 表列默认时间类型设置:数据类型:timestamp,缺省值:CURRENT_TIMESTAMP
- mac 操作idea快捷键
http://blog.csdn.net/rainytooo/article/details/51469126 在mac下idea的常用快捷键如下,下面的快捷键都亲自试用,并有一些和eclipse对比 ...
- ios 读取各种类型文件
1.如何读取UTF-8编码的文本文件? 2.如何读取GB2312(中文)的文本文件? 3.如何读取其它编码文件? 首先解决第一个问题, 1.如何读取UTF-8编码的文本文件? NSString *fi ...
- RDO部署多节点OpenStack Havana(OVS+GRE)
RDO是由红帽RedHat公司推出的部署OpenStack集群的一个基于Puppet的部署工具,可以很快地通过RDO部署一套复杂的OpenStack环境,当前的RDO默认情况下,使用Neutron进行 ...
- LeetCode——Implement Queue using Stacks
Description: Implement the following operations of a queue using stacks. push(x) -- Push element x t ...
- 【BZOJ2087】[Poi2010]Sheep 几何+DP
[BZOJ2087][Poi2010]Sheep Description Lyx的QQ牧场养了很多偶数个的羊,他是Vip,所以牧场是凸多边形(畸形).现在因为他开挂,受到了惩罚,系统要求他把牧场全部分 ...
- JS判断当前是否是IE浏览器,并返回时IE几?
原文参考: https://www.cnblogs.com/liuyanxia/p/5855760.html 具体代码示例: 这里返回的是:如果不是IE浏览器返回 -1 ,返回 7/8/9/10/11 ...
- 安装MySQL与安装Hive
安装mysql 检查是否安装mysql: rpm -qa |grep mysql 删除已经安装的mysql: rpm -e mysql-libs-5.1.71-1.el6.x86_64 报错:因为my ...
- c# BitArray 复制数组 copyto
C# 点阵列(BitArray) BitArray 类管理一个紧凑型的位值数组,它使用布尔值来表示,其中 true 表示位是开启的(1),false 表示位是关闭的(0). C# 拷贝数组的几种方法