当前位置: 首页 > article >正文

Python+Pytorch掌纹训练识别

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

前言

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


文章目录

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

一、所需工具软件

       1. Python
       2. Pycharm

二、使用步骤

代码如下(示例):

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


http://www.kler.cn/a/604567.html

相关文章:

  • STM32八股【1】-----启动流程和startup文件理解
  • [新闻.AI]国产大模型新突破:阿里开源 Qwen2.5-VL-32B 与 DeepSeek 升级 V3 模型
  • Mamba 模型:深度学习序列建模的新突破​
  • 3. 轴指令(omron 机器自动化控制器)——>MC_CamIn
  • 架构设计之自定义延迟双删缓存注解(下)
  • 记录firefly的3566-sdk的下载及解压更新
  • 大模型知识补充四
  • 【AIDevops】驱动无界面自动化运维与分布式脚本系统,初探运维革命之路
  • 蓝桥杯1463:货物摆放问题详解——数学思维与代码优化
  • Vite 创建 Vue3 项目指定 Package name 问题:Invalid package. json name
  • docker使用命令笔记
  • 基于AWS Endpoint Security的合规性保障
  • 【MySQL篇】索引特性,索引的工作原理以及索引的创建与管理
  • 【AI】Orin Nano+ubuntu22.04上移植YoloV11,并使用DeepStream测试成功
  • 数据库中不存在该字段
  • 使用 Python 和 Flask 构建 RESTful API
  • 医学图像分割数据集肺分割数据labelme格式6299张2类别
  • RTSP/Onvif安防监控平台EasyNVR抓包命令tcpdump使用不了,该如何解决?
  • G口服务器和普通服务器之间的区别
  • 人工智能 - SpatialLM:三维空间理解的开源大语言模型