日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > python >内容正文

python

利用卷积神经网络实现人脸识别(python+TensorFlow)

發(fā)布時(shí)間:2024/7/23 python 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 利用卷积神经网络实现人脸识别(python+TensorFlow) 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

利用CNN卷積神經(jīng)網(wǎng)絡(luò)實(shí)現(xiàn)人臉識(shí)別(python+TensorFlow)

使用的人臉數(shù)據(jù)是耶魯大學(xué)的一個(gè)人臉數(shù)據(jù)集Yale_64x64.mat,數(shù)據(jù)集已經(jīng)上傳Yale 64x64.mat

程序:

''''''''' 使用Yale_64x64.mat人臉數(shù)據(jù),利用CNN卷積神經(jīng)網(wǎng)絡(luò)實(shí)現(xiàn)人臉識(shí)別 Yale_64x64.mat數(shù)據(jù)構(gòu)成:分為fea(人臉數(shù)據(jù)165x4096) gnd(標(biāo)簽165x1)圖像大小為64x64(64x64=4096)一共15個(gè)人的人臉,每個(gè)人11條人臉數(shù)據(jù) ''' import tensorflow as tf import numpy as np import scipy.io as siof = open('Yale_64x64.mat','rb') mdict = sio.loadmat(f) # fea:數(shù)據(jù) gnd:標(biāo)簽 train_data = mdict['fea'] train_label = mdict['gnd']# 將數(shù)據(jù)分為訓(xùn)練數(shù)據(jù)與測試數(shù)據(jù) train_data = np.random.permutation(train_data) train_label = np.random.permutation(train_label) test_data = train_data[0:64] test_label = train_label[0:64] np.random.seed(100) test_data = np.random.permutation(test_data) np.random.seed(100) test_label = np.random.permutation(test_label) train_data = train_data.reshape(train_data.shape[0], 64, 64, 1).astype(np.float32)/255# 將標(biāo)簽數(shù)據(jù)改為one_hot編碼格式的數(shù)據(jù) train_labels_new = np.zeros((165, 15)) for i in range(0, 165):j = int(train_label[i, 0])-1train_labels_new[i, j] = 1test_data_input = test_data.reshape(test_data.shape[0], 64, 64, 1).astype(np.float32)/255 test_labels_input = np.zeros((64,15)) for i in range(0,64):j = int(test_label[i, 0])-1test_labels_input[i, j] = 1# CNN data_input = tf.placeholder(tf.float32,[None, 64, 64, 1]) label_input = tf.placeholder(tf.float32,[None, 15])layer1 = tf.layers.conv2d(inputs=data_input, filters=32, kernel_size=2, strides=1, padding='SAME', activation=tf.nn.relu) layer1_pool = tf.layers.max_pooling2d(layer1, pool_size=2, strides=2) layer2 = tf.layers.conv2d(inputs=layer1_pool, filters=64, kernel_size=2, strides=1, padding='SAME', activation=tf.nn.relu) layer2_pool = tf.layers.max_pooling2d(layer2, pool_size=2, strides=2) layer3 = tf.reshape(layer2_pool, [-1,16*16*64]) layer3_relu = tf.layers.dense(layer3,1024, tf.nn.relu) output = tf.layers.dense(layer3_relu, 15)# 計(jì)算損失函數(shù) 最小化損失函數(shù) 計(jì)算測試精確度 loss = tf.losses.softmax_cross_entropy(onehot_labels=label_input, logits=output) train = tf.train.GradientDescentOptimizer(0.01).minimize(loss) accuracy = tf.metrics.accuracy(labels=tf.argmax(label_input,axis=1), predictions=tf.argmax(output, axis=1))[1]# 初始化 運(yùn)行計(jì)算圖 init = tf.group(tf.global_variables_initializer(),tf.local_variables_initializer()) with tf.Session() as sess:sess.run(init)tf.summary.FileWriter('D:/face_log', sess.graph)for i in range(0,1500):train_data_input = np.array(train_data)train_label_input = np.array(train_labels_new)sess.run([train, loss], feed_dict={data_input: train_data_input, label_input: train_label_input})acc = sess.run(accuracy, feed_dict={data_input: test_data_input, label_input: test_labels_input})print('step:%d accuracy:%.2f%%' % (i+1, acc*100))

運(yùn)行結(jié)果:

總結(jié)

以上是生活随笔為你收集整理的利用卷积神经网络实现人脸识别(python+TensorFlow)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。