首页 > 分享 > 卷积神经网络算法(CNN)与PCA+SVC算法的掌纹识别算法对比

卷积神经网络算法(CNN)与PCA+SVC算法的掌纹识别算法对比

100 个手掌,每个手掌 6 个原始图像和 ROI(Region of Interest)图像。ROI表示从原始手掌图像中定位裁剪出的正方形感兴趣区域,尺寸为128×128个像素。

本研究报告使用了两种算法,其中卷积神经网络的精度为0.845,而PCA+SVC算法的精度达到1.

import os
import tensorflow as tf
import numpy as np
from IPython.core.display_functions import clear_output
from keras.preprocessing.image import load_img, img_to_array
from tensorflow import keras
import matplotlib.pyplot as plt

train_images=[]
test_images=[]
train_labels = [i for i in range(100) for _ in range(4)]
test_labels=[i for i in range(100) for _ in range(2)]

data_dir = 'C:/Users/86137/OneDrive/桌面/机器学习/PolyU_Palmprint_600'
# 获取所有图像文件的路径
image_paths = [os.path.join(data_dir, f) for f in os.listdir(data_dir) if f.endswith('.bmp')]
for i in range(0, len(image_paths), 6):
    # 获取每次循环中的6张图像路径
    batch = image_paths[i:i + 6]
    # 将前4张图像路径加入训练集
    train_images.extend(batch[:4])
    # 将后2张图像路径加入测试集
    test_images.extend(batch[4:])

def load_and_process_image(image_path):
    img = load_img(image_path, target_size=(224, 224))  # 加载图像并调整大小
    img_array = img_to_array(img)  # 将图像转换为数组
    img_array = img_array / 255.0  # 归一化处理
    return img_array

# 加载训练集和测试集的图像数据
train_data = np.array([load_and_process_image(image_path) for image_path in train_images])
test_data = np.array([load_and_process_image(image_path) for image_path in test_images])
train_labels = np.array(train_labels)
test_labels = np.array(test_labels)

#三个卷积层,分别包含 32、64 和 128 个滤波器(filter)。每个滤波器的大小为 (3, 3),并采用 ReLU 激活函数。第一层还需要指定输入图像的形状为 (224, 224, 3)
model = keras.models.Sequential([
    tf.keras.layers.Conv2D(32, (3, 3), activation='relu', input_shape=(224, 224, 3)),
    tf.keras.layers.MaxPooling2D((2, 2)),
    tf.keras.layers.Conv2D(64, (3, 3), activation='relu'),
    tf.keras.layers.MaxPooling2D((2, 2)),
    tf.keras.layers.Conv2D(128, (3, 3), activation='relu'),
    tf.keras.layers.Flatten(),
    tf.keras.layers.Dense(128, activation='relu'),
    tf.keras.layers.Dense(100, activation='softmax')
])

# 输出模型的层数和参数数量
model.summary()

# 编译模型
model.compile(optimizer='adam',
              loss='sparse_categorical_crossentropy',
              metrics=['accuracy'])

# 定义一个回调函数,用于绘制训练过程中的准确率变化图表
class PlotAccuracy(tf.keras.callbacks.Callback):
    def on_train_begin(self, logs={}):
        self.i = 0
        self.x = []
        self.acc = []
        self.val_acc = []
        self.fig = plt.figure()

        self.logs = []

    def on_epoch_end(self, epoch, logs={}):
        self.logs.append(logs)
        self.x.append(self.i)
        self.acc.append(logs.get('accuracy'))
        self.val_acc.append(logs.get('val_accuracy'))
        self.i += 1

        clear_output(wait=True)
        plt.plot(self.x, self.acc, label="accuracy")
        plt.plot(self.x, self.val_acc, label="val_accuracy")
        plt.title("Training Progress")
        plt.xlabel("Epochs")
        plt.ylabel("Accuracy")
        plt.legend()
        plt.show()

# 创建回调函数实例
plot_acc = PlotAccuracy()

# 训练模型,并使用回调函数绘制训练过程中的准确率变化图表
history = model.fit(train_data, train_labels, epochs=16, validation_data=(test_data, test_labels), callbacks=[plot_acc])

# 在测试集上评估

相关知识

卷积神经网络的算法范文
【花卉识别系统】Python+卷积神经网络算法+人工智能+深度学习+图像识别+算法模型
花朵识别系统Python+卷积神经网络算法+人工智能+深度学习+计算机课设项目+TensorFlow+模型训练
使用matlab,利用CNN算法实现对蒲公英、玫瑰花、百合花、牵牛花的识别
鲜花分类算法
手写识别技术及其算法分类
毕业设计:基于深度学习的野生花卉识别分类算法系统 目标检测
基于卷积神经网络的花卉识别技术 Flower Recognition Based on Convolutional Neural Networks
卷积神经网络(CNN)鲜花的识别
基于深度卷积神经网络的移动端花卉识别系统

网址: 卷积神经网络算法(CNN)与PCA+SVC算法的掌纹识别算法对比 https://m.huajiangbk.com/newsview1568776.html

所属分类:花卉
上一篇: 秦问雨想睡觉/掌纹识别
下一篇: 使用掌纹线对基于深度学习的掌纹识