基于机器学习和人脸聚类的人脸识别
pyfac的Python项目详细描述
此软件包用于使用机器算法进行人脸识别
需求的安装步骤python包
在ubuntu上安装dlib
以下说明是在Ubuntu16.04上收集的,但也适用于较新版本的Ubuntu16.04。
首先,让我们安装所需的依赖项:
sudo apt-get update
sudo apt-get install build-essential cmake
sudo apt-get install libopenblas-dev liblapack-dev
sudo apt-get install libx11-dev libgtk-3-dev
sudo apt-get install python python-dev python-pip
sudo apt-get install python3 python3-dev python3-pip
之后
pip install dlib
在ubuntu上安装pyfacy模型
pip install pyfacy_dlib_models
在ubuntu上安装imutils
pip install imutils
安装numpy、scipy和sklearn
pip install numpy
pip install scipy
pip install scikit-learn
示例:
读取图像
from pyfacy import utils
img = utils.load_image('<image src>')
ex:
img = utils.load_image('manivannan.jpg')
面部编码:
from pyfacy import utils
img = utils.load_image('<image src>')
encodings = utils.img_to_encodings(img)
比较两个面
from pyfacy import utils
image1 = utils.load_image('<image1 src>')
image2 = utils.load_image('<image2 src>')
matching,distance = utils.compare_faces(image1,image2)
Note: The compare_faces return Boolean and Distance between two faces
使用ml的人脸识别示例
实现算法
- knn-k-最近邻
- Log_Reg_bin-两类逻辑回归
- Log_Reg_mul-具有两个以上类的logistic回归
- 线性判别分析
训练、保存模型和预测图像
from pyfacy import face_recog
from pyfacy import utils
mdl = face_recog.Face_Recog_Algorithm()
# Train the Model
# Implemented only four algorithms above mentioned and put the shortform
mdl.train('pyfacy/Test_DS',alg='LOG_REG_MUL')
# Save the Model
mdl.save_model()
# Predicting Image
img = utils.load_image('<image src>')
mdl.predict(img)
加载模型和预测图像
from pyfacy import face_recog
from pyfacy import utils
mdl = face_recog.Face_Recog_Algorithm()
# Load Model
mdl.load_model('model.pkl')
# Predicting Image
img = utils.load_image('<image src>')
mdl.predict(img)
人脸聚类
对图像进行聚类
from pyfacy import face_clust
# Create object for Cluster class with your source path(only contains jpg images)
mdl = face_clust.Face_Clust_Algorithm('./pyfacy/cluster')
# Load the faces to the algorithm
mdl.load_faces()
# Save the group of images to custom location(if the arg is empty store to current location)
mdl.save_faces('./pyfacy')
from pyfacy import face_clust
# Create object for Cluster class with your source path(only contains jpg images)
mdl = face_clust.Face_Clust_Algorithm('./pyfacy/cluster')
# Load the faces to the algorithm
mdl.load_faces()
# Save the group of images to custom location(if the arg is empty store to current location)
mdl.save_faces('./pyfacy')