資源簡介
原理
人臉框識別
人臉對齊
人臉剪裁
實現
使用webface人臉數據集以及DeepID網絡,通過Caffe訓練出模型參數,得到LFW二分類的人臉識別準確率。下
根據預處理工具進行人臉框檢測,人臉對齊。
預處理工具是其他人寫的,地址:https://github.com/RiweiChen/FaceTools
根據香港中文大學提供的人臉框檢測和人臉特征點檢測的windows二進制程序實現。
http://mmlab.ie.cuhk.edu.hk/archive/CNN_FacePoint.htm

代碼片段和文件信息
#!/usr/bin/env?python
#-*-?coding:utf-8?-*-
‘‘‘
Create?on?Tues?2015-11-24
@author:?hqli
‘‘‘
#運行前先將caffe安裝好放在~/caffe-mater
import?os
class?DeepID():
????#基本屬性
????prj=‘‘#項目名稱
????caffepath=‘‘#caffe主目錄路徑
????prjpath=‘‘#工程的位置
????datapath=‘‘#數據的路徑
????num=0#人數多少
#????ratio=0#訓練數:測試
#????max_iter=0#迭代次數(用于lfw驗證)
#????snapshot=0#迭代多少次保存一次
????
????data_train=‘‘#用于訓練的數據列表
????data_test=‘‘#用于測試的數據列表
????net_proto=‘‘#caffe的Net
????net_proto_model=‘‘
????solver_proto=‘‘#caffe的solver
????solver_proto_model=‘‘
????deploy_proto=‘‘#caffe的deploy
????snapshot_pre=‘‘#訓練好的模型的前綴
????lmdb_train=‘‘#訓練集的lmdb
????lmdb_test=‘‘#測試集的lmdb
????imgmean=‘‘#圖像均值
????netimg=‘‘#net的結構圖像
????log_train=‘‘#caffe的訓練日志
????log_test=‘‘#caffe的測試日志
????log_create=‘‘#轉換lmdb的日志
????#可執行文件
????shcreate=‘‘#將圖像和標簽轉換成lmdb格式
????shimgmean=‘‘#計算圖像均值
????shdrawnet=‘‘#畫Net結構圖
?????
????shtrain=‘‘#訓練
????shtest=‘‘#測試
????def?__init__(selfprjcaffepathprjpathdatapathnum):
????????self.prj=prj
????????self.caffepath=caffepath
????????self.prjpath=self.prjpath
????????self.datapath=datapath
????????self.num=num
#????????self.ratio=ratio
#????????self.itera=max_iter
#????????self.snapshot=snapshot
???????
????????#在prjpath下新建名為num的文件夾將配置以及生成的文件放在該文件夾下
????????#在prjpath下新建num文件夾
????????if?not?os.path.exists(prjpath+str(num)):????
????????????os.makedirs(prjpath+str(num))
????????
????????self.net_proto_model=prjpath+prj+‘_train_test.prototxt‘
????????self.solver_proto_model=prjpath+prj+‘_solver.prototxt‘
????????
????????self.netimg=prjpath+prj+‘_net.png‘
????????self.shdrawnet=prjpath+prj+‘_drawnet.sh‘#畫Net結構圖
????????
????????rspath=prjpath+str(num)+‘/‘
????????strnum=‘_‘+str(num)+‘_‘
??
????????self.data_train=rspath+prj+‘_train_‘+str(num)+‘.txt‘
????????self.data_test=rspath+prj+‘_val_‘+str(num)+‘.txt‘
????????self.net_proto=rspath+prj+strnum+‘train_test.prototxt‘
????????self.solver_proto=rspath+prj+strnum+‘solver.prototxt‘
????????self.deploy_proto=rspath+prj+‘_deploy.prototxt‘
????????self.snapshot_pre=rspath+prj+‘_‘+str(num)
????????
????????self.lmdb_train=rspath+prj+strnum+‘train_lmdb‘
????????self.lmdb_test=rspath+prj+strnum+‘test_lmdb‘????
????????self.imgmean=rspath+prj+strnum+‘mean.binaryproto‘
????????self.log_train=rspath+prj+strnum+‘train.log‘
????????self.log_test=rspath+prj+strnum+‘test.log‘
????????self.log_create=rspath+prj+strnum+‘create.log‘
????????#可執行文件
????????self.shcreate=rspath+prj+strnum+‘create.sh‘#將圖像和標簽轉換成lmdb格式
????????self.shimgmean=rspath+prj+strnum+‘imgmean.sh‘#計算圖像均值
?
????????self.shtrain=rspath+prj+strnum+‘train.sh‘#訓練deepID
????????self.shtest=rspath+prj+strnum+‘test.sh‘#測試deepID
????????
????@staticmethod
????def?fileopt(filenamecontent):
????????fp=open(filename‘w‘)
????????fp.write(content)
????????fp.close()
?
????def?div_data(selfratio):
????????‘‘‘
????????@brief:?將數據集分為訓練集和測試集保存在prjpath下
????????‘‘‘
#????????if?not?os.path.exists(savepath):
#????????????os.makedirs(savepath)
????????dirlists=os.listdir(self.datapath)
?
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2016-04-11?14:10??face_recognition-master\
?????文件???????10697??2016-04-11?14:10??face_recognition-master\DeepID.py
?????文件????????8772??2016-04-11?14:10??face_recognition-master\DeepIDTest.py
?????文件????????3005??2016-04-11?14:10??face_recognition-master\README.md
?????目錄???????????0??2016-04-11?14:10??face_recognition-master\analysis\
?????文件??????980054??2016-04-11?14:10??face_recognition-master\analysis\face_recognition_all.pdf
?????文件????????2487??2016-04-11?14:10??face_recognition-master\deepID_deploy.prototxt
?????文件??????203364??2016-04-11?14:10??face_recognition-master\deepID_net.png
?????文件?????????312??2016-04-11?14:10??face_recognition-master\deepID_solver.prototxt
?????文件????????4972??2016-04-11?14:10??face_recognition-master\deepID_train_test.prototxt
?????文件????????4972??2016-04-11?14:10??face_recognition-master\deepID_train_test_2.prototxt
?????文件????????8198??2016-04-11?14:10??face_recognition-master\lfw_test_deal.py
?????文件??????155334??2016-04-11?14:10??face_recognition-master\pairs.txt
?????目錄???????????0??2016-04-11?14:10??face_recognition-master\res\
?????文件???????21800??2016-04-11?14:10??face_recognition-master\res\ConvNet_structure.png
?????文件??????156657??2016-04-11?14:10??face_recognition-master\res\medium_scales.png
?????文件???????60113??2016-04-11?14:10??face_recognition-master\res\process_all.png
評論
共有 條評論