Python+Pytorch掌纹训练识别

程序示例精选
Python+Pytorch掌纹训练识别
如需安装运行环境或远程调试,见文章底部个人QQ名片,由专业技术人员远程协助!

前言

这篇博客针对《Python+Pytorch掌纹训练识别》编写代码,代码整洁,规则,易读。 学习与应用推荐首选。


文章目录

一、所需工具软件
二、使用步骤
1. 主要代码
2. 运行结果
三、在线协助

一、所需工具软件

1. Python
2. Pycharm

二、使用步骤

代码如下(示例):
cpp 复制代码
import torch 
from torch.utils.data import Dataset, DataLoader
import numpy as np
from models import MyDataset
from models import compnet
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
print('\ndevice-> ', device, '\n\n')
test_set = './data/test.txt'
testset =MyDataset(txt=test_set, transforms=None, train=False)
batch_size = 1
data_loader_test = DataLoader(dataset=testset, batch_size=batch_size, shuffle=False)
net = compnet(num_classes=600) # IITD: 460    KTU: 145    Tongji: 600    REST: 358    XJTU: 200
#net.load_state_dict(torch.load('./pretrained models/net_params.pth'))
net.load_state_dict(torch.load('./pretrained models/net_params_best.pth'))
net.to(device)
net.eval()
# feature extraction:
featDB_test = []
iddb_test = []
with torch.no_grad():
    for batch_id, (data, target) in enumerate(data_loader_test):
        data = data.to(device)
        target = target.to(device)
        # feature extraction
        codes = net.getFeatureCode(data) 
        codes = codes.cpu().detach().numpy()
        y = target.cpu().detach().numpy()
        if batch_id == 0:
            featDB_test = codes
            iddb_test =  y
        else:
            featDB_test = np.concatenate((featDB_test, codes), axis=0)
            iddb_test = np.concatenate((iddb_test, y))
print('completed feature extraction for test set.')
print('(number of samples, feature vector dimensionality): ', featDB_test.shape)
print('\n')
# feature matching: feat1 vs feat2
cosdis =np.dot(feat1,feat2)
dis = np.arccos(np.clip(cosdis, -1, 1))/np.pi # 0~1
print('matching distance, label1 vs label2: \t%.2f, %d vs %d'%(dis, iddb_test[0], iddb_test[1]))

# feature matching: feat1 vs feat3 
cosdis =np.dot(feat1,feat3)
dis = np.arccos(np.clip(cosdis, -1, 1))/np.pi

print('matching distance, label1 vs label3: \t%.2f, %d vs %d'%(dis, iddb_test[0], iddb_test[-1]))
# Match label1 with all other samples
# Match label1 with all other samples
feat1 = featDB_test[0]  # Feature vector of label1
label1 = iddb_test[0]   # Label of the first sample
for i in range(1, len(featDB_test)):
    feat_other = featDB_test[i]  # Feature vector of the other sample
    label_other = iddb_test[i]   # Label of the other sample
    
    # Compute cosine similarity and convert to distance
    cosdis = np.dot(feat1, feat_other)
    dis = np.arccos(np.clip(cosdis, -1, 1)) / np.pi  # Distance in [0, 1]
   
运行结果

三、在线协助:

如需安装运行环境或远程调试,见文章底部个人 QQ 名片,由专业技术人员远程协助!

1)远程安装运行环境,代码调试
2)Visual Studio, Qt, C++, Python编程语言入门指导
3)界面美化
4)软件制作
5)云服务器申请
6)网站制作

当前文章连接: https://blog.csdn.net/alicema1111/article/details/132666851
个人博客主页https://blog.csdn.net/alicema1111?type=blog
博主所有文章点这里: https://blog.csdn.net/alicema1111?type=blog

博主推荐:
Python人脸识别考勤打卡系统:
https://blog.csdn.net/alicema1111/article/details/133434445
Python果树水果识别https://blog.csdn.net/alicema1111/article/details/130862842
Python+Yolov8+Deepsort入口人流量统计: https://blog.csdn.net/alicema1111/article/details/130454430
Python+Qt人脸识别门禁管理系统: https://blog.csdn.net/alicema1111/article/details/130353433
Python+Qt指纹录入识别考勤系统: https://blog.csdn.net/alicema1111/article/details/129338432
Python Yolov5火焰烟雾识别源码分享: https://blog.csdn.net/alicema1111/article/details/128420453
Python+Yolov8路面桥梁墙体裂缝识别: https://blog.csdn.net/alicema1111/article/details/133434445
Python+Yolov5道路障碍物识别: https://blog.csdn.net/alicema1111/article/details/129589741
Python+Yolov5跌倒检测 摔倒检测 人物目标行为 人体特征识别: https://blog.csdn.net/alicema1111/article/details/129272048

相关推荐
牧歌悠悠19 分钟前
【Python 算法】动态规划
python·算法·动态规划
opentrending1 小时前
Github 热点项目 awesome-mcp-servers MCP 服务器合集,3分钟实现AI模型自由操控万物!
服务器·人工智能·github
lisw052 小时前
DeepSeek原生稀疏注意力(Native Sparse Attention, NSA)算法介绍
人工智能·深度学习·算法
Doris Liu.2 小时前
如何检测代码注入(Part 2)
windows·python·安全·网络安全·网络攻击模型
whaosoft-1432 小时前
51c深度学习~合集4
人工智能
逢生博客2 小时前
阿里 FunASR 开源中文语音识别大模型应用示例(准确率比faster-whisper高)
人工智能·python·语音识别·funasr
Android洋芋2 小时前
C语言深度解析:从零到系统级开发的完整指南
c语言·开发语言·stm32·条件语句·循环语句·结构体与联合体·指针基础
bjxiaxueliang2 小时前
一文详解QT环境搭建:Windows使用CLion配置QT开发环境
开发语言·windows·qt
噔噔噔噔@2 小时前
软件测试对于整个行业的重要性及必要性
python·单元测试·压力测试
赵谨言3 小时前
基于Python的Django框架的个人博客管理系统
经验分享·python·毕业设计