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

相关推荐
DO_Community16 小时前
普通服务器都能跑:深入了解 Qwen3-Next-80B-A3B-Instruct
人工智能·开源·llm·大语言模型·qwen
WWZZ202516 小时前
快速上手大模型:机器学习3(多元线性回归及梯度、向量化、正规方程)
人工智能·算法·机器学习·机器人·slam·具身感知
deephub16 小时前
深入BERT内核:用数学解密掩码语言模型的工作原理
人工智能·深度学习·语言模型·bert·transformer
PKNLP16 小时前
BERT系列模型
人工智能·深度学习·bert
应用市场17 小时前
构建自定义命令行工具 - 打造专属指令体
开发语言·windows·python
兰亭妙微17 小时前
ui设计公司审美积累 | 金融人工智能与用户体验 用户界面仪表盘设计
人工智能·金融·ux
东方佑17 小时前
从字符串中提取重复子串的Python算法解析
windows·python·算法
IT_Octopus18 小时前
triton backend 模式docker 部署 pytorch gpu模型 镜像选择
pytorch·docker·triton·模型推理
AKAMAI18 小时前
安全风暴的绝地反击 :从告警地狱到智能防护
运维·人工智能·云计算
岁月宁静18 小时前
深度定制:在 Vue 3.5 应用中集成流式 AI 写作助手的实践
前端·vue.js·人工智能