• 大小: 10.49MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-11-17
  • 语言: Python
  • 标签: LBP  直方图  

资源简介

Python编写的双2D,2DPCA,算法 使用库函数的LBP,直方图算法 余弦相似度,https://blog.csdn.net/u012505617/article/details/89191158 feret人脸库,200人,每人7张;看到大家需要,我就上传了。代码都是我整理的,编写通过的。Oracle数据库之前上传过

资源截图

代码片段和文件信息

# -*- coding: utf-8 -*-
from numpy import *
import numpy as np
import cv2 os math os.path
from skimage.feature import local_binary_pattern
from LBP.LBP3 import LBP2
from LBP.LBP_Ora import (loadImg)
from lbp2D.pca import (pcasucpca)
from lbp2D.td1 import pcasuc2
from LBP.LBP_Ora import (calHistogram)
from sklearn.model_selection import train_test_split
from sklearn.model_selection import GridSearchCV
from sklearn.metrics import classification_report
from sklearn.metrics import confusion_matrix
from sklearn.decomposition import PCA
from sklearn.svm import SVC

def calFenGe(LBPtran1LBptest2):
    numTrain=200
    extrains = np.mat(np.zeros((256*4*7numTrain)))
    extests = np.mat(np.zeros((256*4*7200)))
    for i in range(numTrain):
        exHistogram1 = calHistogram(LBPtran1[:i])
        exHistogram2 = calHistogram(LBptest2[:i])
        extrains[:i] = exHistogram1
        extests[:i] = exHistogram2
    return extrainsextests
def svm_suc2(numberTesttrain_datatest_datay_trainy_testDInd_Icv=5):
    pca2 = PCA(n_components=DInd_I svd_solver=‘randomized‘  # 选择一种svd方式
              whiten=True).fit(train_data)
    X_t1pca = pca2.transform(train_data)#(200 91)
    X_t2pca = pca2.transform(test_data)
    err=0         
    param_grid = {‘C‘: [1 5 10 20304050 1001e3]
                  ‘gamma‘: [0.0001 0.0005 0.001 0.005 0.01 0.10.5] }
#        param_grid ={‘C‘:[20]‘gamma‘:[0.01]}
    clf = GridSearchCV(SVC(kernel=‘rbf‘ class_weight=‘balanced‘)
                       param_grid cv=4)
    clf = clf.fit(X_t1pca y_train)
    print(“索引 {0} 最好参数:\n“.format(i))
    print(clf.best_params_)
    
    y_pred = clf.predict(X_t2pca)
    for i in range(numberTest):
        if y_test[i]!=y_pred[i]:
            err+=1
    print(“正确率%.3f“%(1-err/numberTest))
if __name__==“main“:
    train_data train_lable test_data test_lable=loadImg()#
    LBPtran1=LBP2(train_data)#(10304 200)
    LBptest2=LBP2(test_data) 
    
    Wei=pca(LBPtran1.T0.9)#163
    pcasuc(LBPtran1.T train_lable LBptest2.T test_lableWei)   
    ‘‘‘不分块,之后pca 正确率0.245‘‘‘
    extrainsextests=calFenGe(LBPtran1LBptest2)
    X_train_pca=(extrains.T).A#matrix转array
    X_test_pca=(extests.T).A
    pcasuc2(X_train_pcatrain_lableX_test_pcatest_lable) 
    ‘‘‘分块 直方图 正确率0.910‘‘‘
    
#    array转matrix:用mat()
    ‘‘‘分块之后pca 正确率0.900 ‘‘‘
    train=pca(mat(X_train_pca)0.9)#91
    pcasuc(X_train_pca train_lable X_test_pca test_labletrain)
    
    ‘‘‘分块 pca svm 正确率0.965 ‘‘‘
    svm_suc2(200X_train_pcaX_test_pcatrain_labletest_labletrain)
    
    

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     文件        5866  2019-05-20 19:19  python-lbp-2d\pca.py
     目录           0  2019-05-20 19:10  python-lbp-2d\
     目录           0  2019-05-20 19:10  python-lbp-2d\FERET_80_80\
     目录           0  2019-05-20 19:10  python-lbp-2d\FERET_80_80\FERET-001\
     文件        6690  2003-03-18 19:23  python-lbp-2d\FERET_80_80\FERET-001\01.tif
     文件        6648  2003-04-28 23:10  python-lbp-2d\FERET_80_80\FERET-001\02.tif
     文件        6664  2003-04-28 22:59  python-lbp-2d\FERET_80_80\FERET-001\03.tif
     文件        6688  2003-04-28 23:07  python-lbp-2d\FERET_80_80\FERET-001\04.tif
     文件        6676  2003-04-29 00:52  python-lbp-2d\FERET_80_80\FERET-001\05.tif
     文件        6682  2003-03-18 19:23  python-lbp-2d\FERET_80_80\FERET-001\06.tif
     文件        6650  2003-03-18 19:23  python-lbp-2d\FERET_80_80\FERET-001\07.tif
     文件       47616  2008-01-10 18:35  python-lbp-2d\FERET_80_80\FERET-001\Thumbs.db
     目录           0  2019-05-20 19:10  python-lbp-2d\FERET_80_80\FERET-002\
     文件        6666  2003-03-18 19:23  python-lbp-2d\FERET_80_80\FERET-002\01.tif
     文件        6706  2003-04-28 23:11  python-lbp-2d\FERET_80_80\FERET-002\02.tif
     文件        6692  2003-04-28 22:59  python-lbp-2d\FERET_80_80\FERET-002\03.tif
     文件        6682  2003-04-28 23:07  python-lbp-2d\FERET_80_80\FERET-002\04.tif
     文件        6692  2003-04-29 00:52  python-lbp-2d\FERET_80_80\FERET-002\05.tif
     文件        6684  2003-03-18 19:23  python-lbp-2d\FERET_80_80\FERET-002\06.tif
     文件        6620  2003-03-18 19:23  python-lbp-2d\FERET_80_80\FERET-002\07.tif
     文件       45056  2008-10-27 15:47  python-lbp-2d\FERET_80_80\FERET-002\Thumbs.db
     目录           0  2019-05-20 19:10  python-lbp-2d\FERET_80_80\FERET-003\
     文件        6674  2003-03-18 21:42  python-lbp-2d\FERET_80_80\FERET-003\01.tif
     文件        6682  2003-04-28 23:11  python-lbp-2d\FERET_80_80\FERET-003\02.tif
     文件        6696  2003-04-28 22:59  python-lbp-2d\FERET_80_80\FERET-003\03.tif
     文件        6688  2003-04-28 23:07  python-lbp-2d\FERET_80_80\FERET-003\04.tif
     文件        6686  2003-04-29 00:52  python-lbp-2d\FERET_80_80\FERET-003\05.tif
     文件        6688  2003-03-18 21:42  python-lbp-2d\FERET_80_80\FERET-003\06.tif
     文件        6700  2003-03-18 21:42  python-lbp-2d\FERET_80_80\FERET-003\07.tif
     文件       46592  2009-10-27 22:11  python-lbp-2d\FERET_80_80\FERET-003\Thumbs.db
     目录           0  2019-05-20 19:10  python-lbp-2d\FERET_80_80\FERET-004\
............此处省略1779个文件信息

评论

共有 条评论