91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 14.64MB
    文件類型: .rar
    金幣: 1
    下載: 0 次
    發(fā)布日期: 2023-07-22
  • 語言: 其他
  • 標(biāo)簽:

資源簡介

《DeepLearning tutorial(5)CNN卷積神經(jīng)網(wǎng)絡(luò)應(yīng)用于人臉識(shí)別(詳細(xì)流程+代碼實(shí)現(xiàn))》這篇文章的代碼,將CNN用于人臉識(shí)別,整個(gè)實(shí)現(xiàn)流程請(qǐng)見:http://blog.csdn.net/u012162613/article/details/43277187

資源截圖

代碼片段和文件信息

#?-*-coding:utf8-*-#
“““
本程序基于python+numpy+theano+PIL開發(fā),采用類似LeNet5的CNN模型,應(yīng)用于olivettifaces人臉數(shù)據(jù)庫,
實(shí)現(xiàn)人臉識(shí)別的功能,模型的誤差降到了5%以下。
本程序只是個(gè)人學(xué)習(xí)過程的一個(gè)toy?implement,模型可能存在overfitting,因?yàn)闃颖拘?,這一點(diǎn)也無從驗(yàn)證。

但是,本程序意在理清程序開發(fā)CNN模型的具體步驟,特別是針對(duì)圖像識(shí)別,從拿到圖像數(shù)據(jù)庫,到實(shí)現(xiàn)一個(gè)針對(duì)這個(gè)圖像數(shù)據(jù)庫的CNN模型,
我覺得本程序?qū)@些流程的實(shí)現(xiàn)具有參考意義。

@author:wepon(http://2hwp.com)
講解這份代碼的文章:http://blog.csdn.net/u012162613/article/details/43277187
“““
import?os
import?sys
import?time

import?numpy
from?PIL?import?Image

import?theano
import?theano.tensor?as?T
from?theano.tensor.signal?import?downsample
from?theano.tensor.nnet?import?conv

“““
加載圖像數(shù)據(jù)的函數(shù)dataset_path即圖像olivettifaces的路徑
加載olivettifaces后,劃分為train_datavalid_datatest_data三個(gè)數(shù)據(jù)集
函數(shù)返回train_datavalid_datatest_data以及對(duì)應(yīng)的label
“““
def?load_data(dataset_path):
????img?=?Image.open(dataset_path)
????img_ndarray?=?numpy.asarray(img?dtype=‘float64‘)/256
????faces=numpy.empty((4002679))
????for?row?in?range(20):
???for?column?in?range(20):
faces[row*20+column]=numpy.ndarray.flatten(img_ndarray?[row*57:(row+1)*57column*47:(column+1)*47])

????label=numpy.empty(400)
????for?i?in?range(40):
label[i*10:i*10+10]=i
????label=label.astype(numpy.int)

????#分成訓(xùn)練集、驗(yàn)證集、測(cè)試集,大小如下
????train_data=numpy.empty((3202679))
????train_label=numpy.empty(320)
????valid_data=numpy.empty((402679))
????valid_label=numpy.empty(40)
????test_data=numpy.empty((402679))
????test_label=numpy.empty(40)

????for?i?in?range(40):
train_data[i*8:i*8+8]=faces[i*10:i*10+8]
train_label[i*8:i*8+8]=label[i*10:i*10+8]
valid_data[i]=faces[i*10+8]
valid_label[i]=label[i*10+8]
test_data[i]=faces[i*10+9]
test_label[i]=label[i*10+9]

????#將數(shù)據(jù)集定義成shared類型,才能將數(shù)據(jù)復(fù)制進(jìn)GPU,利用GPU加速程序。
????def?shared_dataset(data_x?data_y?borrow=True):
????????shared_x?=?theano.shared(numpy.asarray(data_x
???????????????????????????????????????????????dtype=theano.config.floatX)
?????????????????????????????????borrow=borrow)
????????shared_y?=?theano.shared(numpy.asarray(data_y
???????????????????????????????????????????????dtype=theano.config.floatX)
?????????????????????????????????borrow=borrow)
????????return?shared_x?T.cast(shared_y?‘int32‘)



????train_set_x?train_set_y?=?shared_dataset(train_datatrain_label)
????valid_set_x?valid_set_y?=?shared_dataset(valid_datavalid_label)
????test_set_x?test_set_y?=?shared_dataset(test_datatest_label)
????rval?=?[(train_set_x?train_set_y)?(valid_set_x?valid_set_y)
????????????(test_set_x?test_set_y)]
????return?rval



#分類器,即CNN最后一層,采用邏輯回歸(softmax)
class?LogisticRegression(object):
????def?__init__(self?input?n_in?n_out):
????????self.W?=?theano.shared(
????????????value=numpy.zeros(
????????????????(n_in?n_out)
????????????????dtype=theano.config.floatX
????????????)
????????????name=‘W‘
????????????borrow=True
????????)
????????self.b?=?theano.shared(
????????????value=numpy.zeros(
????????????????(n_out)
????????????????dtype=theano.config.floatX
????????????)
????????????name=‘b‘
????????????borrow=True
????????)
????????self.p_y_given_x?=?T.nnet.softm

?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----

?????文件????1182905??2015-01-27?10:53??FaceRecognition_CNN(olivettifaces)\olivettifaces.gif

?????文件???14750086??2015-01-29?15:30??FaceRecognition_CNN(olivettifaces)\params.pkl

?????文件??????15554??2015-01-30?07:21??FaceRecognition_CNN(olivettifaces)\train_CNN_olivettifaces.py

?????文件???????7042??2015-01-30?07:21??FaceRecognition_CNN(olivettifaces)\use_CNN_olivettifaces.py

?????目錄??????????0??2015-01-30?07:18??FaceRecognition_CNN(olivettifaces)

-----------?---------??----------?-----??----

?????????????15955587????????????????????5


評(píng)論

共有 條評(píng)論

相關(guān)資源