使用LBP特征提取对FG-NET数据集进行年龄估计

1 篇文章 0 订阅
import os
import cv2
import xlwt
import xlrd
import numpy as np
from skimage import feature as skif
from sklearn.model_selection import train_test_split
from sklearn.svm import SVC
from sklearn.metrics import accuracy_score, mean_absolute_error, f1_score, mutual_info_score
from sklearn.metrics.pairwise import pairwise_kernels, pairwise_distances
from sklearn.base import ClassifierMixin, BaseEstimator
from sklearn.utils.validation import check_X_y
from sklearn import preprocessing



def getLbpData(image, hist_size=256, lbp_radius=1, lbp_point=8):
    image = cv2.resize(image, (300, 300), interpolation=cv2.INTER_CUBIC)
    # 使用LBP方法提取图像的纹理特征.
    lbp = skif.local_binary_pattern(image, lbp_point, lbp_radius, 'default')
    # 统计图像的直方图
    max_bins = int(lbp.max() + 1)
    # hist size:256
    hist, _ = np.histogram(lbp, normed=True, bins=max_bins, range=(0, max_bins))
    return hist



data = []
label = []

IMAGES_DIR = os.path.join(os.path.dirname(__file__), r'D:\FG-NET\ImagesClear')
book = xlrd.open_workbook(r"D:\FG-NET\meta.xls")
table = book.sheet_by_index(0)
for name in table.col_values(0):
    print(name)
    image = cv2.imread(os.path.join(IMAGES_DIR, name),0)
    # print(image)
    lbpdata = getLbpData(image)
    data.append(lbpdata)
for lab in table.col_values(2):
    label.append(lab)





data = np.array(data)
print(data.shape)
label = np.array(label)
print(label.shape)

train_X,test_X,train_y,test_y = train_test_split(data,label,test_size=0.5)

model = SVC(kernel='rbf',C=0.01)
model.fit(train_X,train_y)
y_hat = model.predict(test_X)
ACC = accuracy_score(y_hat, test_y)
MAE = mean_absolute_error(y_hat, test_y)
MI = mutual_info_score(y_hat, test_y)
print("ACC===",ACC)
print("MAE===",MAE)
print("MI===",MI)








  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

DeniuHe

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值