计算机竞赛 基于深度学习的人脸性别年龄识别 - 图像识别 opencv

文章目录

  • 0 前言
  • 1 课题描述
  • 2 实现效果
  • 3 算法实现原理
    • 3.1 数据集
    • 3.2 深度学习识别算法
    • 3.3 特征提取主干网络
    • 3.4 总体实现流程
  • 4 具体实现
    • 4.1 预训练数据格式
    • 4.2 部分实现代码
  • 5 最后

0 前言

🔥 优质竞赛项目系列,今天要分享的是

🚩 毕业设计 人脸性别年龄识别系统 - 图像识别 opencv

该项目较为新颖,适合作为竞赛课题方向,学长非常推荐!

🥇学长这里给一个题目综合评分(每项满分5分)

  • 难度系数:3分
  • 工作量:3分
  • 创新点:3分

🧿 更多资料, 项目分享:

https://gitee.com/dancheng-senior/postgraduate

1 课题描述

随着大数据与人工智能逐渐走入人们的生活,计算机视觉应用越发广泛。如医疗影像识别、无人驾驶车载视觉、通用物体识别、自然场景下的文本识别等,根据不同的应用场景,人脸研究方向可以分为人脸检测、身份识别、性别识别、年龄预测、种族识别、表情识别等。近年来,人脸身份识别技术发展迅猛,在生活应用中取得了较好的效果,也逐渐趋于成熟,而年龄识别与性别预测,仍然是生物特征识别研究领域中一项具有挑战性的课题。

课题意义

相比人脸性别属性而言,人脸年龄属性的研究更富有挑战性。主要有两点原因,首先每个人的年龄会随着身体健康状况、皮肤保养情况而表现得有所不同,即便是在同一年,表现年龄会随着个人状态的不同而改变,人类识别尚且具有较高难度。其次,可用的人脸年龄估计数据集比较少,不同年龄的数据标签收集不易,现有大多数的年龄数据集都是在不同的复杂环境下的照片、人脸图片存在光照变化较复杂、部分遮挡、图像模糊、姿态旋转角度较大等一系列问题,对人脸模型的鲁棒性产生了较大的影响。

2 实现效果

这里废话不多说,先放上大家最关心的实现效果:

输入图片:
在这里插入图片描述

识别结果:

在这里插入图片描述

或者实时检测
在这里插入图片描述
在这里插入图片描述

3 算法实现原理

3.1 数据集

学长收集的数据集:
该人脸数据库的图片来源于互联网的爬取,而非研究机构整理,一共含有13000多张人脸图像,在这个数据集中大约有1860张图片是成对出现的,即同一个人的2张不同照片,有助于人脸识别算法的研究,图像标签中标有人的身份信息,人脸坐标,关键点信息,可用于人脸检测和人脸识别的研究,此数据集是对人脸算法效果验证的权威数据集.

在这里插入图片描述
该数据集包含的人脸范围比较全面,欧亚人种都有。

3.2 深度学习识别算法

卷积神经网络是常见的深度学习架构,而在CNN出现之前,图像需要处理的数据量过大,导致成本很高,效率很低,图像在数字化的过程中很难保留原有的特征,导致图像处理的准确率不高。CNN的出现使得提取特征的能力变得更强,为更多优秀网络的研究提供了有力的支撑。CNN的核心思想是利用神经网络模拟人脑视觉神经系统,构造多个神经元并建立彼此之间的联系。不同的神经元进行分工,浅层神经元处理低纬度图像特征,深层神经元处理图像高级特征、语义信息等,CNN的网络结构主要由卷积层、BN层、激活层、池化层、全连接层、损失函数层构成,多个层协同工作实现了特征提取的功能,并通过特有的网络结构降低参数的数量级,防止过拟合,最终得到输出结果.

CNN传承了多层感知机的思想,并受到了生物神经科学的启发,通过卷积的运算模拟人类视觉皮层的“感受野”。不同于传统的前馈神经网络,卷积运算对图像的区域值进行加权求和,最终以神经元的形式进行输出。前馈神经网络对每一个输入的信号进行加权求和:

  • (a)图是前馈神经网络的连接方式
  • (b)图是CNN的连接方式。

在这里插入图片描述
cnn框架如下:
在这里插入图片描述

3.3 特征提取主干网络

在深度学习算法研究中,通用主干特征提取网络结合特定任务网络已经成为一种标准的设计模式。特征提取对于分类、识别、分割等任务都是至关重要的部分。下面介绍本文研究中用到的主干神经网络。

ResNet网络
ResNet是ILSVRC-2015的图像分类任务冠军,也是CVPR2016的最佳论文,目前应用十分广泛,ResNet的重要性在于将网络的训练深度延伸到了数百层,而且取得了非常好的效果。在ResNet出现之前,网络结构一般在20层左右,对于一般情况,网络结构越深,模型效果就会越好,但是研究人员发现加深网络反而会使结果变差。

在这里插入图片描述

人脸特征提取我这里选用ResNet,网络结构如下:
在这里插入图片描述

3.4 总体实现流程

在这里插入图片描述

4 具体实现

4.1 预训练数据格式

在这里插入图片描述

在这里插入图片描述

4.2 部分实现代码

训练部分代码:

from __future__ import absolute_importfrom __future__ import divisionfrom __future__ import print_functionfrom six.moves import xrangefrom datetime import datetimeimport timeimport osimport numpy as npimport tensorflow as tffrom data import distorted_inputsfrom model import select_modelimport jsonimport reLAMBDA = 0.01MOM = 0.9tf.app.flags.DEFINE_string('pre_checkpoint_path', '',"""If specified, restore this pretrained model """"""before beginning any training.""")tf.app.flags.DEFINE_string('train_dir', '/home/dpressel/dev/work/AgeGenderDeepLearning/Folds/tf/test_fold_is_0','Training directory')tf.app.flags.DEFINE_boolean('log_device_placement', False,"""Whether to log device placement.""")tf.app.flags.DEFINE_integer('num_preprocess_threads', 4,'Number of preprocessing threads')tf.app.flags.DEFINE_string('optim', 'Momentum','Optimizer')tf.app.flags.DEFINE_integer('image_size', 227,'Image size')tf.app.flags.DEFINE_float('eta', 0.01,'Learning rate')tf.app.flags.DEFINE_float('pdrop', 0.,'Dropout probability')tf.app.flags.DEFINE_integer('max_steps', 40000,'Number of iterations')tf.app.flags.DEFINE_integer('steps_per_decay', 10000,'Number of steps before learning rate decay')tf.app.flags.DEFINE_float('eta_decay_rate', 0.1,'Learning rate decay')tf.app.flags.DEFINE_integer('epochs', -1,'Number of epochs')tf.app.flags.DEFINE_integer('batch_size', 128,'Batch size')tf.app.flags.DEFINE_string('checkpoint', 'checkpoint','Checkpoint name')tf.app.flags.DEFINE_string('model_type', 'default','Type of convnet')tf.app.flags.DEFINE_string('pre_model','',#'./inception_v3.ckpt','checkpoint file')FLAGS = tf.app.flags.FLAGS# Every 5k steps cut learning rate in halfdef exponential_staircase_decay(at_step=10000, decay_rate=0.1):print('decay [%f] every [%d] steps' % (decay_rate, at_step))def _decay(lr, global_step):return tf.train.exponential_decay(lr, global_step,at_step, decay_rate, staircase=True)return _decaydef optimizer(optim, eta, loss_fn, at_step, decay_rate):global_step = tf.Variable(0, trainable=False)optz = optimif optim == 'Adadelta':optz = lambda lr: tf.train.AdadeltaOptimizer(lr, 0.95, 1e-6)lr_decay_fn = Noneelif optim == 'Momentum':optz = lambda lr: tf.train.MomentumOptimizer(lr, MOM)lr_decay_fn = exponential_staircase_decay(at_step, decay_rate)return tf.contrib.layers.optimize_loss(loss_fn, global_step, eta, optz, clip_gradients=4., learning_rate_decay_fn=lr_decay_fn)def loss(logits, labels):labels = tf.cast(labels, tf.int32)cross_entropy = tf.nn.sparse_softmax_cross_entropy_with_logits(logits=logits, labels=labels, name='cross_entropy_per_example')cross_entropy_mean = tf.reduce_mean(cross_entropy, name='cross_entropy')tf.add_to_collection('losses', cross_entropy_mean)losses = tf.get_collection('losses')regularization_losses = tf.get_collection(tf.GraphKeys.REGULARIZATION_LOSSES)total_loss = cross_entropy_mean + LAMBDA * sum(regularization_losses)tf.summary.scalar('tl (raw)', total_loss)#total_loss = tf.add_n(losses + regularization_losses, name='total_loss')loss_averages = tf.train.ExponentialMovingAverage(0.9, name='avg')loss_averages_op = loss_averages.apply(losses + [total_loss])for l in losses + [total_loss]:tf.summary.scalar(l.op.name + ' (raw)', l)tf.summary.scalar(l.op.name, loss_averages.average(l))with tf.control_dependencies([loss_averages_op]):total_loss = tf.identity(total_loss)return total_lossdef main(argv=None):with tf.Graph().as_default():model_fn = select_model(FLAGS.model_type)# Open the metadata file and figure out nlabels, and size of epochinput_file = os.path.join(FLAGS.train_dir, 'md.json')print(input_file)with open(input_file, 'r') as f:md = json.load(f)images, labels, _ = distorted_inputs(FLAGS.train_dir, FLAGS.batch_size, FLAGS.image_size, FLAGS.num_preprocess_threads)logits = model_fn(md['nlabels'], images, 1-FLAGS.pdrop, True)total_loss = loss(logits, labels)train_op = optimizer(FLAGS.optim, FLAGS.eta, total_loss, FLAGS.steps_per_decay, FLAGS.eta_decay_rate)saver = tf.train.Saver(tf.global_variables())summary_op = tf.summary.merge_all()sess = tf.Session(config=tf.ConfigProto(log_device_placement=FLAGS.log_device_placement))tf.global_variables_initializer().run(session=sess)# This is total hackland, it only works to fine-tune iv3if FLAGS.pre_model:inception_variables = tf.get_collection(tf.GraphKeys.VARIABLES, scope="InceptionV3")restorer = tf.train.Saver(inception_variables)restorer.restore(sess, FLAGS.pre_model)if FLAGS.pre_checkpoint_path:if tf.gfile.Exists(FLAGS.pre_checkpoint_path) is True:print('Trying to restore checkpoint from %s' % FLAGS.pre_checkpoint_path)restorer = tf.train.Saver()tf.train.latest_checkpoint(FLAGS.pre_checkpoint_path)print('%s: Pre-trained model restored from %s' %(datetime.now(), FLAGS.pre_checkpoint_path))run_dir = '%s/run-%d' % (FLAGS.train_dir, os.getpid())checkpoint_path = '%s/%s' % (run_dir, FLAGS.checkpoint)if tf.gfile.Exists(run_dir) is False:print('Creating %s' % run_dir)tf.gfile.MakeDirs(run_dir)tf.train.write_graph(sess.graph_def, run_dir, 'model.pb', as_text=True)tf.train.start_queue_runners(sess=sess)summary_writer = tf.summary.FileWriter(run_dir, sess.graph)steps_per_train_epoch = int(md['train_counts'] / FLAGS.batch_size)num_steps = FLAGS.max_steps if FLAGS.epochs < 1 else FLAGS.epochs * steps_per_train_epochprint('Requested number of steps [%d]' % num_steps)for step in xrange(num_steps):start_time = time.time()_, loss_value = sess.run([train_op, total_loss])duration = time.time() - start_timeassert not np.isnan(loss_value), 'Model diverged with loss = NaN'if step % 10 == 0:num_examples_per_step = FLAGS.batch_sizeexamples_per_sec = num_examples_per_step / durationsec_per_batch = float(duration)format_str = ('%s: step %d, loss = %.3f (%.1f examples/sec; %.3f ' 'sec/batch)')print(format_str % (datetime.now(), step, loss_value,examples_per_sec, sec_per_batch))# Loss only actually evaluated every 100 steps?if step % 100 == 0:summary_str = sess.run(summary_op)summary_writer.add_summary(summary_str, step)if step % 1000 == 0 or (step + 1) == num_steps:saver.save(sess, checkpoint_path, global_step=step)if __name__ == '__main__':tf.app.run()

5 最后

🧿 更多资料, 项目分享:

https://gitee.com/dancheng-senior/postgraduate

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/99760.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Java版工程行业管理系统源码-专业的工程管理软件- 工程项目各模块及其功能点清单

Java版工程项目管理系统 Spring CloudSpring BootMybatisVueElementUI前后端分离 功能清单如下&#xff1a; 首页 工作台&#xff1a;待办工作、消息通知、预警信息&#xff0c;点击可进入相应的列表 项目进度图表&#xff1a;选择&#xff08;总体或单个&#xff09;项目显示…

Si24R2F+畜牧 耳标测体温开发资料

Si24R2F是针对IOT应用领域推出的新款超低功耗2.4G内置NVM单发射芯片。广泛应用于2.4G有源活体动物耳标&#xff0c;带实时测温计步功能。相较于Si24R2E&#xff0c;Si24R2F增加了温度监控、自动唤醒间隔功能&#xff1b;发射功率由7dBm增加到12dBm&#xff0c;距离更远&#xf…

2024腾讯校招后端面试真题汇总及其解答(三)

21【算法题】反转链表 题目: 给定单链表的头节点 head ,请反转链表,并返回反转后的链表的头节点。 示例 1: 输入:head = [1,2,3,4,5] 输出:[5,4,3,2,1]示例 2: 输入:head = [1,2] 输出:[2,1]示例 3: 输入:head = [] 输出:[]提示: 链表中节点的数目范围是 [0, 5…

通过nginx将https协议反向代理到http协议请求上

通过nginx将https协议反向代理到http协议请求上 1、问题背景2、介绍nginx的反向代理功能及配置https协议3、具体实现3.1 后端服务支持方式3.2 nginx重定向方式 3.3、nginx的反向代理方式4、关于nginx常用模块和指令 1、问题背景 目前一个系统仅支持https协议访问&#xff0c;因…

ElasticSearch详解

目录 一、Elasticsearch是什么&#xff1f; 二、为什么要使用ElasticSearch 2.1 关系型数据库有什么问题&#xff1f; 2.2 ElasticSearch有什么优势&#xff1f; 2.3 ES使用场景 三、ElasticSearch概念、原理与实现 3.1 搜索引擎原理 3.2 Lucene 倒排索引核心原理 倒排…

Mysql高阶语句(二)

一、设置别名&#xff08;alias ——>as&#xff09; 在 MySQL 查询时&#xff0c;当表的名字比较长或者表内某些字段比较长时&#xff0c;为了方便书写或者 多次使用相同的表&#xff0c;可以给字段列或表设置别名。使用的时候直接使用别名&#xff0c;简洁明了&#xff0…

Python爬虫乱码问题之encoding和apparent_encoding的区别

encoding是从http中的header中的charset字段中提取的编码方式&#xff0c;若header中没有charset字段则默认为ISO-8859-1编码模式&#xff0c;则无法解析中文&#xff0c;这是乱码的原因 apparent_encoding会从网页的内容中分析网页编码的方式&#xff0c;所以apparent_encodi…

vscode使用delve调试golang程序

环境配置 delve仓库&#xff0c;含有教程&#xff1a;https://github.com/go-delve/delve golang的debugging教程&#xff1a;https://github.com/golang/vscode-go/wiki/debugging > go version go version go1.20 windows/amd64> go install github.com/go-delve/de…

我国智慧燃气建设应用过程中,有哪些关键问题?

关键词&#xff1a;智慧燃气、智慧燃气系统、智能燃气、燃气智能管控、数字孪生、智慧燃气平台 国内智慧燃气建设应用过程中需要解决以下4个关键问题&#xff1a; 01 广泛生产单元的感知能力建设方面的问题 智慧燃气的核心特征是“智慧”&#xff0c;具备“三个实现”即实现…

rk3568 SDK的buildroot添加package

开发源码工程 首先进入<SDK>/app 目录下&#xff0c;在该目录下创建一个名为“mypackage”的文件夹。 在 mypackage 目录下创建一个.c 源文件 main.c&#xff0c;以及一个 Makefile 文件。 大家可以自己在 main.c 源文件中编写一个简单的测试代码&#xff0c;譬如打印一…

Unity 切换场景后场景变暗

问题 Unity版本&#xff1a;2019.4.34f1c1 主场景只有UI&#xff0c;没有灯光&#xff0c;天空盒&#xff1b;其他场景有灯光和天空盒所有场景不烘焙主场景作为启动场景运行&#xff0c;切换到其他场景&#xff0c;场景变暗某一个场景作为启动场景运行&#xff0c;光影效果正…

Python怎么实现更高效的数据结构和算法? - 易智编译EaseEditing

要实现更高效的数据结构和算法&#xff0c;你可以考虑以下几个方面的优化&#xff1a; 选择合适的数据结构&#xff1a; 选择最适合你问题的数据结构至关重要。例如&#xff0c;如果需要频繁插入和删除操作&#xff0c;可能链表比数组更合适。如果需要高效查找操作&#xff0…