科普知识
ACM 国际多媒体会议(ACM International Conference on Multimedia)是计算机科学领域中多媒体领域的首要国际会议。多媒体研究的重点是整合不同数字形式(包括图像,文本,视频,音乐,传感器数据,口头音频)提供的多种视角。自1993年以来,ACM多媒体一直将学术界和工业界的研究人员和从业人员汇聚在一起,提出创新的研究成果并讨论最新进展。
# 前言 #
在理论篇的上一篇文章中我们学习了DenseNet网络结构,虽然没有认真分析每一层的参数,但我相信按照之前的进度,同时结合原始论文中给出的架构,大家应该可以很容易的推断出每一层的维度变化。该网络的核心在于特征复用,每一个密集块中每一层都包含了前面的所有输入,由此在一定程度上实现了丰富特征表征的目的和缓解了梯度消失的问题。
TensorFlow之DenseNet实战
下面,我们将从数据准备到模型构建一一为各位分享基于DenseNet网络的人脸表情识别模型,模型有所精简,望各位仔细阅读哦!
1.数据准备
本次数据采用FERPlus人脸表情数据集,包含八个分类:平和,开心,悲伤,惊讶,厌恶,愤怒,害怕。与之前的数据集类似,但是多了一个蔑视的表情。
2.网络结构
原始论文中给出最少的结构是121层,我们刚开始学,其实没有必要设计这么深,因此,我们的对应上图稍微改了一下结构,主要层数分布从6-12-24-16改为2-4-8-4,由此可以在一定程度上缓解硬件不足的问题,当然,这样做一般来说精度会有所下降,不过没关系,我们学习的是网络的构建思想而不是网络构建本身。
# 密集块定义
def Dense_Block(name,input, inchannel, DB_nums):
conv_inchannel = inchannel
for i in range(DB_nums):
out = Conv_layer('Dense_Block{}__1_{}'.format(name, i), input, [1,1,inchannel,32], [32], [1,1,1,1])
# print("******** out1 {} ".format(out.shape))
out = Conv_layer('Dense_Block{}__3_{}'.format(name, i), out, [3,3,32,32], [32], [1,1,1,1])
# print("******** out2 {} ".format(out.shape))
out = tf.concat([input, out], axis=3)
inchannel = out.get_shape().as_list()[3]
input = out
return out
# 过渡层
def Transition_Layer(names, input):
in_inchannel = input.get_shape().as_list()[3]
out_channel = int(in_inchannel * 0.5)
out = Conv_layer('Transition_Layer_{}'.format(names), input, [1,1,in_inchannel,out_channel], [out_channel], [1,1,1,1])
out = Max_pool_lrn(names = 'pooling_{}'.format(names), input = out , ksize = [1, 3, 3, 1], is_lrn = False)
return out
# print("******** out {} ".format(out.shape))
# 分类层
def Class_Layer(input, n_classes):
out = tf.nn.avg_pool(input, ksize=[1,7,7,1],strides=[1,7,7,1],padding='SAME')
out = tf.squeeze(out)
print("******** out {} ".format(out.shape))
with tf.variable_scope('softmax_linear') as scope:
weights = tf.Variable(tf.truncated_normal(shape=[out.get_shape().as_list()[-1], n_classes], stddev=0.005, dtype=tf.float32),
name='softmax_linear', dtype=tf.float32)
biases = tf.Variable(tf.constant(value=0.1, dtype=tf.float32, shape=[n_classes]),
name='biases', dtype=tf.float32)
out = tf.add(tf.matmul(out, weights), biases, name='softmax_linear')
return out
网络代码:
对于网络训练这一块我们就暂时不分享了,大家主要记得DenseNet网络的
特点是特征复用,进而构建深层次神经网络哦。
结语
本期分享到此结束了,大家最好能够下去进行实操哦,如果需要源码可以后台回复:文章名+代码索取,对于后期文章,我们将逐步采用Pytorch进行实战,希望各位老铁做好心理准备哈。
编辑:玥怡居士|审核:世外居士