资源简介
利用Python实现的BP神经网络进行人脸识别,源码公开,打开就能使用,欢迎大家学习借鉴,进制使用于非法用途或者有损他人利益。
代码片段和文件信息
#coding=utf8
from neuralnetworktool import *
import random
import traceback
class Neuron():
def __init__(selfnInput = 0studyspeed = 1thresholdFunc = sigmoidX):
self.nInput = nInput
#init the weight in range -1 to 1
randomweights = [random.uniform(-1 1) for i in range(nInput)]
self.weights = randomweights
self.thresholdFunc = thresholdFunc
self.studyspeed = studyspeed
self.inputs = []
def setInputs(selfinputs):
self.inputs = inputs
def getInputs(self):
return self.inputs
def getOutput(selfinputs):
self.inputs = inputs
outputs = np.squeeze(np.asarray(self.weights * inputs))
#for i in range(len(self.weights)):
# outputs += self.weights[i] * self.inputs[i]
return round(self.thresholdFunc(outputs)3)
def adjustWeights(selfinputsexceptOutputrealOutput = None):
if realOutput == None:
f = self.getOutput(inputs)
else:
f = realOutput
d = exceptOutput
r = (d - f) * f * (1 - f)
self.adjustWeightsWithR(r)
return r
#R反映出网络输出的平方差对相应的sigmoid函数的输入中的变化的敏感度
def adjustWeightsWithR(selfR):
self.weights += self.studyspeed * R * np.transpose(self.inputs)
def getWeights(self):
return np.squeeze(np.asarray(self.weights))
def getWeightsMatrix(self):
return self.weights
def setWeights(selfweights):
self.weights = np.matrix(weights)
def setStudySpeed(selfstudyspeed):
self.studyspeed = studyspeed
def printInfo(self):
print self.weights
class NeuralNetWork():
def __init__(selfnInput=0nHide=0nOutput=0studyspeed=0):
self.nInput = nInput
self.nHide = nHide
self.nOutput = nOutput
self.studyspeed = studyspeed
self.inputNeurons = [0 for i in range(nInput)]
self.hideNeurons = [
Neuron(nInput = nInputstudyspeed = studyspeed) for i in range(nHide)]
self.outputNeurons = [
Neuron(nInput = nHidestudyspeed = studyspeed) for i in range(nOutput)]
def backpropagation(selftrainings=[]examples=[]):
for i in range(len(trainings)):
self.backpropagationSingle(
training = trainings[i]
example = examples[i]
)
def backpropagationSingle(selftrainingexample):
#d为训练集目标输出
d = example
#输入转化为单列矩阵
self.inputNeurons = np.transpose(np.matrix(training))
#用于保存隐藏层输出
hideoutputs = []
#对输入层作为输入,得到隐藏层输出结果
for hideNeuron in self.hideNeurons:
hideoutputs.append(hideNeuron.getOutput(self.inputNeurons))
#将隐藏层结果作为输出层的输入,得到输出层的结果
outputlayeroutputs = []
hideOutPutMatrixs = np.transpose(np.matrix(hideoutputs))
for outputNeuron in self.outputNeurons:
outputlayeroutputs.append(outputNeuron.getOutput(hideOutPutMatrixs))
#输出层结果与期望结果做比较,并且反向传播调节
#保存调节前输出层权值
beforeweights = []
#对输出层进行调节
#保存输出层各个神经元的调节因子
outputRs = []
for i in range(self.nOutput):
#f为实际输出结果
f = outputlayeroutputs[i]
outputR = (d[i] - f) * f * (1 - f)
outputRs.append(outputR)
#保存第i个输出神经元的调节前权值
beforeweights.append(self.outputNeurons[i].getWeights())
#对每个输出层神经元进行调节
self.outputNeurons[i].adjustWeightsWithR(outputR)
#对隐藏层进行调节
for i in range(s
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2016-05-05 03:06 NeuralNetwork-master\
文件 378 2016-05-05 03:06 NeuralNetwork-master\.gitattributes
文件 655 2016-05-05 03:06 NeuralNetwork-master\.gitignore
文件 744 2016-05-05 03:06 NeuralNetwork-master\README.md
文件 0 2016-05-05 03:06 NeuralNetwork-master\TestConfig.txt
目录 0 2016-05-05 03:06 NeuralNetwork-master\data\
目录 0 2016-05-05 03:06 NeuralNetwork-master\data\faces\
文件 131 2016-05-05 03:06 NeuralNetwork-master\data\faces\.anonr
目录 0 2016-05-05 03:06 NeuralNetwork-master\data\faces\an2i\
文件 42648 2016-05-05 03:06 NeuralNetwork-master\data\faces\an2i\an2i_left_angry_open.pgm
文件 3853 2016-05-05 03:06 NeuralNetwork-master\data\faces\an2i\an2i_left_angry_open_2.pgm
文件 973 2016-05-05 03:06 NeuralNetwork-master\data\faces\an2i\an2i_left_angry_open_4.pgm
文件 42480 2016-05-05 03:06 NeuralNetwork-master\data\faces\an2i\an2i_left_angry_sunglasses.pgm
文件 3853 2016-05-05 03:06 NeuralNetwork-master\data\faces\an2i\an2i_left_angry_sunglasses_2.pgm
文件 973 2016-05-05 03:06 NeuralNetwork-master\data\faces\an2i\an2i_left_angry_sunglasses_4.pgm
文件 42802 2016-05-05 03:06 NeuralNetwork-master\data\faces\an2i\an2i_left_happy_open.pgm
文件 3853 2016-05-05 03:06 NeuralNetwork-master\data\faces\an2i\an2i_left_happy_open_2.pgm
文件 973 2016-05-05 03:06 NeuralNetwork-master\data\faces\an2i\an2i_left_happy_open_4.pgm
文件 42944 2016-05-05 03:06 NeuralNetwork-master\data\faces\an2i\an2i_left_happy_sunglasses.pgm
文件 3853 2016-05-05 03:06 NeuralNetwork-master\data\faces\an2i\an2i_left_happy_sunglasses_2.pgm
文件 973 2016-05-05 03:06 NeuralNetwork-master\data\faces\an2i\an2i_left_happy_sunglasses_4.pgm
文件 43292 2016-05-05 03:06 NeuralNetwork-master\data\faces\an2i\an2i_left_neutral_open.pgm
文件 3853 2016-05-05 03:06 NeuralNetwork-master\data\faces\an2i\an2i_left_neutral_open_2.pgm
文件 973 2016-05-05 03:06 NeuralNetwork-master\data\faces\an2i\an2i_left_neutral_open_4.pgm
文件 42974 2016-05-05 03:06 NeuralNetwork-master\data\faces\an2i\an2i_left_neutral_sunglasses.pgm
文件 3853 2016-05-05 03:06 NeuralNetwork-master\data\faces\an2i\an2i_left_neutral_sunglasses_2.pgm
文件 973 2016-05-05 03:06 NeuralNetwork-master\data\faces\an2i\an2i_left_neutral_sunglasses_4.pgm
文件 42693 2016-05-05 03:06 NeuralNetwork-master\data\faces\an2i\an2i_left_sad_open.pgm
文件 3853 2016-05-05 03:06 NeuralNetwork-master\data\faces\an2i\an2i_left_sad_open_2.pgm
文件 973 2016-05-05 03:06 NeuralNetwork-master\data\faces\an2i\an2i_left_sad_open_4.pgm
文件 42967 2016-05-05 03:06 NeuralNetwork-master\data\faces\an2i\an2i_left_sad_sunglasses.pgm
............此处省略1896个文件信息
相关资源
- python3.5 百度ai人脸识别
- python基于人脸检测和人脸识别
- Python-pytorch实现的人脸检测和人脸识别
- dlib-19.18.0-cp37-cp37m-linux_armv7l.whl
- 人脸识别算法,双2D2DPCALBP余弦相似度
- MATLAB版本的2Dpca和欧式距离算法
- Python-PCA降维人脸识别,已包含yale数据
- 人脸识别算法 python
- dlib18.17 编译好的python-dlib库 不需要
- python人脸识别截取
- 人脸识别图片集(刘德华吴彦祖)
- 利用python和opencv进行人脸识别
- 人脸识别-python-特征脸-PCA
- opencv3+python人脸检测和识别- 完整实战
- 人脸识别python代码187268
- opencv3+python人脸检测和识别- 完整实战
- opencv3+python人脸检测和识别 完整项目
- dlib-19.17.0-py3.7-win-amd64.egg.zip免去复杂
- 西电数据挖掘作业——VSM人脸识别算
- 基于Tensorflow的人脸识别源码
-
树莓派人脸识别python代码及xm
l模型 - python + opencv 人脸识别代码(可以跨平
- python人脸识别
- 人脸识别门禁系统 毕业设计 可移植
- Python人脸识别自动筛选抖音女神小姐
- python调用dlib库实现简单的人脸识别
- 基于人脸识别的课堂签到管理系统.
- 人脸识别代码python
- LBPH算法人脸识别代码.rar
- 基于卷积神经网络的人脸识别
评论
共有 条评论