脸型分类-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)>和<深 ...
随机推荐
- Vue检测当前是否处于mock模式
Vue检测当前是否处于mock模式 1.在main.js中声明全局变量: import Vue from 'vue' /* 全局变量 */ var GLOBAL_VARIABLE = { isMock ...
- c# FileStream 类构造函数
- MySQL之Prepared Statements
1.概述 prepared statement在MySQL4.1中引进并且增加了一些新的命令: COM_STMT_PREPARE COM_STMT_EXECUTE COM_STMT_CLOSE COM ...
- 16寸屏苹果MacBook Pro悄悄上市,售价18999 元起步
传闻了半年之久的16寸屏苹果MacBook Pro于11月13日夜晚终于上线,15寸的机身16寸的屏幕,相比于此前的13寸和15寸MacBook Pro,新品搭配了更大的屏幕.更高性能的处理器以及更大 ...
- 【编程开发】Python隐藏属性——使用双下划线标识私有属性,外部不可直接访问
from:https://zhuanlan.zhihu.com/p/30553607 小编在最初使用上Python之后,就一发不可收拾,人生苦短.我用Python,不光是因为其优雅简洁, ...
- python算法与数据结构-算法介绍(31)
一.算法和数据结构 什么是算法和数据结构?如果将最终写好运行的程序比作战场,我们程序员便是指挥作战的将军,而我们所写的代码便是士兵和武器. 那么数据结构和算法是什么?答曰:兵法!故,数据结构和算法是一 ...
- npm run build 时的 warning
entrypoint size limit: The following entrypoint(s) combined asset size exceeds the recommended limit ...
- 5、Hadoop 2.6.5 环境搭建
下载 地址:http://archive.apache.org/dist/hadoop/common/ sudo wget http://archive.apache.org/dist/hadoop/ ...
- HDU6072 Logical Chain
题意:动态修改图 \(G\) 的边集,求每次修改后的 \(\sum c\times (c−1) / 2\) (记每个强连通分量中的点数量为 \(c\) ).其中修改操作共 \(m\) 次,每次最多改 ...
- python 使用 tibco ems
emshelper.py #encoding=utf-8 import jpype jvmpath=r"C:\Program Files\Java\jre1.8.0_161\bin\serv ...