資源簡介
基于Python3.7實現人臉圖像特征提取與對比,調用NMF算法和PCA算法。包括源程序和結果圖片。

代碼片段和文件信息
from?numpy.random?import?RandomState
import?matplotlib.pyplot?as?plt
from?sklearn.datasets?import?fetch_olivetti_faces
from?sklearn?import?decomposition
?
?
n_row?n_col?=?2?3
n_components?=?n_row?*?n_col
image_shape?=?(64?64)
?
?
###############################################################################
#?Load?faces?data
dataset?=?fetch_olivetti_faces(shuffle=True?random_state=RandomState(0))
faces?=?dataset.data
?
###############################################################################
def?plot_gallery(title?images?n_col=n_col?n_row=n_row):
????plt.figure(figsize=(2.?*?n_col?2.26?*?n_row))?
????plt.suptitle(title?size=16)
?
????for?i?comp?in?enumerate(images):
????????plt.subplot(n_row?n_col?i?+?1)
????????vmax?=?max(comp.max()?-comp.min())
?
????????plt.imshow(comp.reshape(image_shape)?cmap=plt.cm.gray
???????????????????interpolation=‘nearest‘?vmin=-vmax?vmax=vmax)
????????plt.xticks(())
????????plt.yticks(())
????plt.subplots_adjust(0.01?0.05?0.99?0.94?0.04?0.)
?
?????
plot_gallery(“First?centered?Olivetti?faces“?faces[:n_components])
###############################################################################
?
estimators?=?[
????(‘Eigenfaces?-?PCA?using?randomized?SVD‘
?????????decomposition.PCA(n_components=6whiten=True))
?
????(‘Non-negative?components?-?NMF‘
?????????decomposition.NMF(n_components=6?init=‘nndsvda‘?tol=5e-3))
]
?
###############################################################################
?
for?name?estimator?in?estimators:
????print(“Extracting?the?top?%d?%s...“?%?(n_components?name))
????print(faces.shape)
????estimator.fit(faces)
????components_?=?estimator.components_
????plot_gallery(name?components_[:n_components])
?
plt.show()
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件??????42672??2018-07-11?22:47??人臉圖像特征提取與對比\Figure_1.png
?????文件??????42610??2018-07-11?22:47??人臉圖像特征提取與對比\Figure_2.png
?????文件??????36555??2018-07-11?22:47??人臉圖像特征提取與對比\Figure_3.png
?????文件???????1788??2017-06-13?23:30??人臉圖像特征提取與對比\NMF、PCA-人臉圖像特征抽取與對比.py
?????目錄??????????0??2018-07-11?22:47??人臉圖像特征提取與對比
-----------?---------??----------?-----??----
???????????????123625????????????????????5
評論
共有 條評論