用php做網(wǎng)站用什么框架百度域名查詢官網(wǎng)
文章目錄
- 0 前言
- 1 課題描述
- 2 實(shí)現(xiàn)效果
- 3 算法實(shí)現(xiàn)原理
- 3.1 數(shù)據(jù)集
- 3.2 深度學(xué)習(xí)識別算法
- 3.3 特征提取主干網(wǎng)絡(luò)
- 3.4 總體實(shí)現(xiàn)流程
- 4 具體實(shí)現(xiàn)
- 4.1 預(yù)訓(xùn)練數(shù)據(jù)格式
- 4.2 部分實(shí)現(xiàn)代碼
- 5 最后
0 前言
🔥 優(yōu)質(zhì)競賽項(xiàng)目系列,今天要分享的是
🚩 畢業(yè)設(shè)計(jì) 人臉性別年齡識別系統(tǒng) - 圖像識別 opencv
該項(xiàng)目較為新穎,適合作為競賽課題方向,學(xué)長非常推薦!
🥇學(xué)長這里給一個(gè)題目綜合評分(每項(xiàng)滿分5分)
- 難度系數(shù):3分
- 工作量:3分
- 創(chuàng)新點(diǎn):3分
🧿 更多資料, 項(xiàng)目分享:
https://gitee.com/dancheng-senior/postgraduate
1 課題描述
隨著大數(shù)據(jù)與人工智能逐漸走入人們的生活,計(jì)算機(jī)視覺應(yīng)用越發(fā)廣泛。如醫(yī)療影像識別、無人駕駛車載視覺、通用物體識別、自然場景下的文本識別等,根據(jù)不同的應(yīng)用場景,人臉研究方向可以分為人臉檢測、身份識別、性別識別、年齡預(yù)測、種族識別、表情識別等。近年來,人臉身份識別技術(shù)發(fā)展迅猛,在生活應(yīng)用中取得了較好的效果,也逐漸趨于成熟,而年齡識別與性別預(yù)測,仍然是生物特征識別研究領(lǐng)域中一項(xiàng)具有挑戰(zhàn)性的課題。
課題意義
相比人臉性別屬性而言,人臉年齡屬性的研究更富有挑戰(zhàn)性。主要有兩點(diǎn)原因,首先每個(gè)人的年齡會隨著身體健康狀況、皮膚保養(yǎng)情況而表現(xiàn)得有所不同,即便是在同一年,表現(xiàn)年齡會隨著個(gè)人狀態(tài)的不同而改變,人類識別尚且具有較高難度。其次,可用的人臉年齡估計(jì)數(shù)據(jù)集比較少,不同年齡的數(shù)據(jù)標(biāo)簽收集不易,現(xiàn)有大多數(shù)的年齡數(shù)據(jù)集都是在不同的復(fù)雜環(huán)境下的照片、人臉圖片存在光照變化較復(fù)雜、部分遮擋、圖像模糊、姿態(tài)旋轉(zhuǎn)角度較大等一系列問題,對人臉模型的魯棒性產(chǎn)生了較大的影響。
2 實(shí)現(xiàn)效果
這里廢話不多說,先放上大家最關(guān)心的實(shí)現(xiàn)效果:
輸入圖片:
識別結(jié)果:
或者實(shí)時(shí)檢測
3 算法實(shí)現(xiàn)原理
3.1 數(shù)據(jù)集
學(xué)長收集的數(shù)據(jù)集:
該人臉數(shù)據(jù)庫的圖片來源于互聯(lián)網(wǎng)的爬取,而非研究機(jī)構(gòu)整理,一共含有13000多張人臉圖像,在這個(gè)數(shù)據(jù)集中大約有1860張圖片是成對出現(xiàn)的,即同一個(gè)人的2張不同照片,有助于人臉識別算法的研究,圖像標(biāo)簽中標(biāo)有人的身份信息,人臉坐標(biāo),關(guān)鍵點(diǎn)信息,可用于人臉檢測和人臉識別的研究,此數(shù)據(jù)集是對人臉?biāo)惴ㄐЧ?yàn)證的權(quán)威數(shù)據(jù)集.
該數(shù)據(jù)集包含的人臉范圍比較全面,歐亞人種都有。
3.2 深度學(xué)習(xí)識別算法
卷積神經(jīng)網(wǎng)絡(luò)是常見的深度學(xué)習(xí)架構(gòu),而在CNN出現(xiàn)之前,圖像需要處理的數(shù)據(jù)量過大,導(dǎo)致成本很高,效率很低,圖像在數(shù)字化的過程中很難保留原有的特征,導(dǎo)致圖像處理的準(zhǔn)確率不高。CNN的出現(xiàn)使得提取特征的能力變得更強(qiáng),為更多優(yōu)秀網(wǎng)絡(luò)的研究提供了有力的支撐。CNN的核心思想是利用神經(jīng)網(wǎng)絡(luò)模擬人腦視覺神經(jīng)系統(tǒng),構(gòu)造多個(gè)神經(jīng)元并建立彼此之間的聯(lián)系。不同的神經(jīng)元進(jìn)行分工,淺層神經(jīng)元處理低緯度圖像特征,深層神經(jīng)元處理圖像高級特征、語義信息等,CNN的網(wǎng)絡(luò)結(jié)構(gòu)主要由卷積層、BN層、激活層、池化層、全連接層、損失函數(shù)層構(gòu)成,多個(gè)層協(xié)同工作實(shí)現(xiàn)了特征提取的功能,并通過特有的網(wǎng)絡(luò)結(jié)構(gòu)降低參數(shù)的數(shù)量級,防止過擬合,最終得到輸出結(jié)果.
CNN傳承了多層感知機(jī)的思想,并受到了生物神經(jīng)科學(xué)的啟發(fā),通過卷積的運(yùn)算模擬人類視覺皮層的“感受野”。不同于傳統(tǒng)的前饋神經(jīng)網(wǎng)絡(luò),卷積運(yùn)算對圖像的區(qū)域值進(jìn)行加權(quán)求和,最終以神經(jīng)元的形式進(jìn)行輸出。前饋神經(jīng)網(wǎng)絡(luò)對每一個(gè)輸入的信號進(jìn)行加權(quán)求和:
- (a)圖是前饋神經(jīng)網(wǎng)絡(luò)的連接方式
- (b)圖是CNN的連接方式。
cnn框架如下:
3.3 特征提取主干網(wǎng)絡(luò)
在深度學(xué)習(xí)算法研究中,通用主干特征提取網(wǎng)絡(luò)結(jié)合特定任務(wù)網(wǎng)絡(luò)已經(jīng)成為一種標(biāo)準(zhǔn)的設(shè)計(jì)模式。特征提取對于分類、識別、分割等任務(wù)都是至關(guān)重要的部分。下面介紹本文研究中用到的主干神經(jīng)網(wǎng)絡(luò)。
ResNet網(wǎng)絡(luò)
ResNet是ILSVRC-2015的圖像分類任務(wù)冠軍,也是CVPR2016的最佳論文,目前應(yīng)用十分廣泛,ResNet的重要性在于將網(wǎng)絡(luò)的訓(xùn)練深度延伸到了數(shù)百層,而且取得了非常好的效果。在ResNet出現(xiàn)之前,網(wǎng)絡(luò)結(jié)構(gòu)一般在20層左右,對于一般情況,網(wǎng)絡(luò)結(jié)構(gòu)越深,模型效果就會越好,但是研究人員發(fā)現(xiàn)加深網(wǎng)絡(luò)反而會使結(jié)果變差。
人臉特征提取我這里選用ResNet,網(wǎng)絡(luò)結(jié)構(gòu)如下:
3.4 總體實(shí)現(xiàn)流程
4 具體實(shí)現(xiàn)
4.1 預(yù)訓(xùn)練數(shù)據(jù)格式
4.2 部分實(shí)現(xiàn)代碼
訓(xùn)練部分代碼:
?
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 最后
🧿 更多資料, 項(xiàng)目分享:
https://gitee.com/dancheng-senior/postgraduate