脸型分类-Face shape classification using Inception v3
本文链接:https://blog.csdn.net/u011961856/article/details/77984667
函数解析
github 代码:https://github.com/adonistio/inception-face-shape-classifier
CLASSIFY_FACE.py
1
用于运行训练好的Inception model,对输入图像进行分类.
CLASSIFY_FACE_CONFUSION.py
1
与CLASSIFY_FACE.PY类似,但是讲述如结果和一个困惑度矩阵保存在文本文件中.
EXTRACT_FEATURES.py
1
这个脚本用于检测图像中的人脸,即bounding box,检测特征点,并提取人脸特征用于训练.
PROCESS_IMAGE.py
1
包含几个图像预处理和增强函数,例如图像平方,滤波,模糊,旋转,翻转等.
RETRAIN_CMDGEN.py
1
得到CMD窗口命令,以重新训练Inception V3 model.
RETRAIN_v2.py
1
将测试图片设置为包含所有的图像,解决了验证时的double counting 等问题.
TRAIN_CLASSIFIERS.py
1
用于训练LDA, SVM-LIN, SVM-RBF, MLP, KNN分类模型.
bottlenecks.rar
1
包含所有500张图像的bottleneck files, bottleneck files为图像的向量表示,向量为Inception model的最后一层的输出.
features.txt
1
包含LDA,SVM,KNN,MLP分类中使用的特征向量.
原理
inceptionV2网络结构:
采用inceptionV2,对图像,提取一个2048维的特征向量.由于我们需要将输入图像分为5个类别,因此需要添加网络层,网络层的输入为2048维的向量,输出为5维的特征向量.
具体为将特征向量输入一个全连接层,得到5维的特征向量,之后加一个softmax激活函数,得到输出概率:
# Add the new layer that we'll be training.
(train_step, cross_entropy, bottleneck_input, ground_truth_input,
final_tensor) = add_final_training_ops(len(image_lists.keys()),
FLAGS.final_tensor_name,
bottleneck_tensor)
1
2
3
4
5
def add_final_training_ops(class_count, final_tensor_name, bottleneck_tensor):
with tf.name_scope('input'):
bottleneck_input = tf.placeholder_with_default(
bottleneck_tensor, shape=[None, BOTTLENECK_TENSOR_SIZE],
name='BottleneckInputPlaceholder')#[batch_size,2048]
ground_truth_input = tf.placeholder(tf.float32,
[None, class_count],
name='GroundTruthInput')
# Organizing the following ops as `final_training_ops` so they're easier
# to see in TensorBoard
layer_name = 'final_training_ops'
with tf.name_scope(layer_name):
with tf.name_scope('weights'):
layer_weights = tf.Variable(tf.truncated_normal([BOTTLENECK_TENSOR_SIZE, class_count], stddev=0.001), name='final_weights')
variable_summaries(layer_weights)
with tf.name_scope('biases'):
layer_biases = tf.Variable(tf.zeros([class_count]), name='final_biases')
variable_summaries(layer_biases)
with tf.name_scope('Wx_plus_b'):
logits = tf.matmul(bottleneck_input, layer_weights) + layer_biases
tf.summary.histogram('pre_activations', logits)
final_tensor = tf.nn.softmax(logits, name=final_tensor_name)
tf.summary.histogram('activations', final_tensor)
with tf.name_scope('cross_entropy'):
cross_entropy = tf.nn.softmax_cross_entropy_with_logits(
labels=ground_truth_input, logits=logits)
with tf.name_scope('total'):
cross_entropy_mean = tf.reduce_mean(cross_entropy)
tf.summary.scalar('cross_entropy', cross_entropy_mean)
with tf.name_scope('train'):
train_step = tf.train.GradientDescentOptimizer(FLAGS.learning_rate).minimize(
cross_entropy_mean)
return (train_step, cross_entropy_mean, bottleneck_input, ground_truth_input,
final_tensor)
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
模型训练
inception模型训练函数为retrain_v2.py,训练命令为:
python retrain_v2.py –image_dir /home/qinghua/data/face_classify/celebs3_squared/
训练输入数据为,人脸图像(长度为2048的特征向量),根据inceptionv2网络计算所有的训练,验证,测试数据的特征向量(bottleneck),并将其保存在bootlneck文件假下,每个图像的特征向量对应一个文本文件,文件名为filename.txt.
label为长度为5的向量,需要训练的为添加的全连接层的权重矩阵w([2048,5]),b([5,]).
迭代4000次的结果:
脸型分类-Face shape classification using Inception v3的更多相关文章
- 源码分析——迁移学习Inception V3网络重训练实现图片分类
1. 前言 近些年来,随着以卷积神经网络(CNN)为代表的深度学习在图像识别领域的突破,越来越多的图像识别算法不断涌现.在去年,我们初步成功尝试了图像识别在测试领域的应用:将网站样式错乱问题.无线领域 ...
- 微调Inception V3网络-对Satellite分类
目录 1. 流程概述 2. 准备数据集 2.1 Satellite数据集介绍 3. Inception V3网络 4. 训练 4.1 基于Keras微调Inception V3网络 4.2 Keras ...
- 经典分类CNN模型系列其五:Inception v2与Inception v3
经典分类CNN模型系列其五:Inception v2与Inception v3 介绍 Inception v2与Inception v3被作者放在了一篇paper里面,因此我们也作为一篇blog来对其 ...
- 1、VGG16 2、VGG19 3、ResNet50 4、Inception V3 5、Xception介绍——迁移学习
ResNet, AlexNet, VGG, Inception: 理解各种各样的CNN架构 本文翻译自ResNet, AlexNet, VGG, Inception: Understanding va ...
- 从损失函数优化角度:讨论“线性回归(linear regression)”与”线性分类(linear classification)“的联系与区别
1. 主要观点 线性模型是线性回归和线性分类的基础 线性回归和线性分类模型的差异主要在于损失函数形式上,我们可以将其看做是线性模型在多维空间中“不同方向”和“不同位置”的两种表现形式 损失函数是一种优 ...
- 从GoogLeNet至Inception v3
从GoogLeNet至Inception v3 一.CNN发展纵览 我们先来看一张图片: 1985年,Rumelhart和Hinton等人提出了后向传播(Back Propagation,BP)算法( ...
- Inception V3 的 tensorflow 实现
tensorflow 官方给出的实现:models/inception_v3.py at master · tensorflow/models · GitHub 1. 模型结构 首先来看 Incept ...
- 网络结构解读之inception系列四:Inception V3
网络结构解读之inception系列四:Inception V3 Inception V3根据前面两篇结构的经验和新设计的结构的实验,总结了一套可借鉴的网络结构设计的原则.理解这些原则的背后隐藏的 ...
- 深度学习面试题29:GoogLeNet(Inception V3)
目录 使用非对称卷积分解大filters 重新设计pooling层 辅助构造器 使用标签平滑 参考资料 在<深度学习面试题20:GoogLeNet(Inception V1)>和<深 ...
随机推荐
- error 106: Can't Access ASP.NET\ClientFiles\
Error 1606 Can’t access ASP.NET\ClientFiles\ when installing Crystal Reports Support Pack 10 Sea ...
- 学习python的日常3
python的一些高级特性: 切片(跟名字一样,把一个完整的东西选取一部分自己想要的去切下来):通过切片可以快速的去除一些元素,只要确定好索引位置,避免的循环导致的多写代码 数组,元组,字符串都可以用 ...
- SpringBoot使用MockMVC单元测试Controller
对模块进行集成测试时,希望能够通过输入URL对Controller进行测试,如果通过启动服务器,建立http client进行测试,这样会使得测试变得很麻烦,比如,启动速度慢,测试验证不方便,依赖网络 ...
- windows+phpstudy(apache) 以cgi方式运行python
Apache配置 在httpd.conf中查找DocumentRoot: +ExecCGI 支持cgi DocumentRoot "F:\phpStud\PHPTutorial\WWW&qu ...
- System V共享内存
目录 1. 概述 2. System V共享内存API shmget shmat shmdt shmctl 3. 简单的程序 代码实现 common.h shmcreate.c shmrmid.c s ...
- Linux命令——readlink、realpath
参考:Linux命令——ln Linux readlink and realpath Command Tutorial for Beginners (with Examples) 简介 ln命令允许你 ...
- h5中history实例
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- bcb中TParamter传NULL值
if (status_Desc.IsEmpty()) Queue_Status->Value = Null(); else Queue_Status->Value = status_Des ...
- 解决jdbc向数据库存入数据出现乱码的情况
解决办法 1.修改项目的编码,建议统一使用utf-8来实现,这样整个项目就是utf-8. 2.jdbc:mysql://locathost:3306/数据库名称?useUnicode=true& ...
- onclick与click的区别
用法: Obj.click(function(){ }); Obj.onclick=function(){ } 相同:效果一样. 区别: 用户或浏览器执行的某种动作,例如click load,mous ...