两张人像对比是否是同一人- deep-person-reid

2024-08-21 16:44

本文主要是介绍两张人像对比是否是同一人- deep-person-reid,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

基于的项目:https://github.com/KaiyangZhou/deep-person-reid

安装

git clone https://github.com/KaiyangZhou/deep-person-reid.gitcd deep-person-reid/pip install -r requirements.txtpython setup.py develop

权重下载

https://kaiyangzhou.github.io/deep-person-reid/MODEL_ZOO

在这里插入图片描述

reid.py

执行:

python reid.py --image_path1 input/1.jpg --image_path2 input/2.jpg 
'''
python reid.py --image_path1 input/1.jpg --image_path2 input/2.jpg 
'''
import torchreid
import torch
from PIL import Image
from torchreid.utils import FeatureExtractor
import argparse# Initialize the feature extractor with a pretrained model
extractor = FeatureExtractor(model_name='osnet_x1_0',  # You can choose other models too, like 'resnet50', 'resnet101'model_path='osnet_x1_0_imagenet.pth',  # None to use default pretrained model# device='cuda'  # or 'cpu'device='cpu'  # or 'cpu'
)def extract_feature(image_path):# 直接传递图像路径给 FeatureExtractorfeatures = extractor([image_path])  # Extract featuresreturn features[0]  # Return the feature vectordef compare_images(image_path1, image_path2):# Extract features from both imagesfeatures1 = extract_feature(image_path1)features2 = extract_feature(image_path2)# Compute the cosine similaritysimilarity = torch.nn.functional.cosine_similarity(features1, features2, dim=0)return similarity.item()if __name__ == "__main__":parser = argparse.ArgumentParser()parser.add_argument('--image_path1', type=str, default='1.jpg')parser.add_argument('--image_path2', type=str, default='2.jpg')opt = parser.parse_args()image_path1 = opt.image_path1image_path2 = opt.image_path2similarity_score = compare_images(image_path1, image_path2)threshold = 0.7  # Adjust this threshold based on your use caseif similarity_score > threshold:print("The images are likely of the same person.")else:print("The images are likely of different people.")

结果

在这里插入图片描述
在这里插入图片描述
Model: osnet_x1_0

  • params: 2,193,616
  • flops: 978,878,352
    Successfully loaded pretrained weights from “osnet_x1_0_imagenet.pth”
    ** The following layers are discarded due to unmatched keys or layer size: [‘classifier.weight’, ‘classifier.bias’]
    The images are likely of different people.

在这里插入图片描述
在这里插入图片描述
Model: osnet_x1_0

  • params: 2,193,616
  • flops: 978,878,352
    Successfully loaded pretrained weights from “osnet_x1_0_imagenet.pth”
    ** The following layers are discarded due to unmatched keys or layer size: [‘classifier.weight’, ‘classifier.bias’]
    The images are likely of the same person.

这篇关于两张人像对比是否是同一人- deep-person-reid的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1093720

相关文章

Go语言如何判断两张图片的相似度

《Go语言如何判断两张图片的相似度》这篇文章主要为大家详细介绍了Go语言如何中实现判断两张图片的相似度的两种方法,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 在介绍技术细节前,我们先来看看图片对比在哪些场景下可以用得到:图片去重:自动删除重复图片,为存储空间"瘦身"。想象你是一个

Linux中的more 和 less区别对比分析

《Linux中的more和less区别对比分析》在Linux/Unix系统中,more和less都是用于分页查看文本文件的命令,但less是more的增强版,功能更强大,:本文主要介绍Linu... 目录1. 基础功能对比2. 常用操作对比less 的操作3. 实际使用示例4. 为什么推荐 less?5.

基于Go语言实现Base62编码的三种方式以及对比分析

《基于Go语言实现Base62编码的三种方式以及对比分析》Base62编码是一种在字符编码中使用62个字符的编码方式,在计算机科学中,,Go语言是一种静态类型、编译型语言,它由Google开发并开源,... 目录一、标准库现状与解决方案1. 标准库对比表2. 解决方案完整实现代码(含边界处理)二、关键实现细

PostgreSQL 序列(Sequence) 与 Oracle 序列对比差异分析

《PostgreSQL序列(Sequence)与Oracle序列对比差异分析》PostgreSQL和Oracle都提供了序列(Sequence)功能,但在实现细节和使用方式上存在一些重要差异,... 目录PostgreSQL 序列(Sequence) 与 oracle 序列对比一 基本语法对比1.1 创建序

exfat和ntfs哪个好? U盘格式化选择NTFS与exFAT的详细区别对比

《exfat和ntfs哪个好?U盘格式化选择NTFS与exFAT的详细区别对比》exFAT和NTFS是两种常见的文件系统,它们各自具有独特的优势和适用场景,以下是关于exFAT和NTFS的详细对比... 无论你是刚入手了内置 SSD 还是便携式移动硬盘或 U 盘,都需要先将它格式化成电脑或设备能够识别的「文

Python实现Microsoft Office自动化的几种方式及对比详解

《Python实现MicrosoftOffice自动化的几种方式及对比详解》办公自动化是指利用现代化设备和技术,代替办公人员的部分手动或重复性业务活动,优质而高效地处理办公事务,实现对信息的高效利用... 目录一、基于COM接口的自动化(pywin32)二、独立文件操作库1. Word处理(python-d

Java常用注解扩展对比举例详解

《Java常用注解扩展对比举例详解》:本文主要介绍Java常用注解扩展对比的相关资料,提供了丰富的代码示例,并总结了最佳实践建议,帮助开发者更好地理解和应用这些注解,需要的朋友可以参考下... 目录一、@Controller 与 @RestController 对比二、使用 @Data 与 不使用 @Dat

python中字符串拼接的几种方法及优缺点对比详解

《python中字符串拼接的几种方法及优缺点对比详解》在Python中,字符串拼接是常见的操作,Python提供了多种方法来拼接字符串,每种方法有其优缺点和适用场景,以下是几种常见的字符串拼接方法,需... 目录1. 使用 + 运算符示例:优缺点:2. 使用&nbsjsp;join() 方法示例:优缺点:3

C++ 各种map特点对比分析

《C++各种map特点对比分析》文章比较了C++中不同类型的map(如std::map,std::unordered_map,std::multimap,std::unordered_multima... 目录特点比较C++ 示例代码 ​​​​​​代码解释特点比较1. std::map底层实现:基于红黑

Golang中拼接字符串的6种方式性能对比

《Golang中拼接字符串的6种方式性能对比》golang的string类型是不可修改的,对于拼接字符串来说,本质上还是创建一个新的对象将数据放进去,主要有6种拼接方式,下面小编就来为大家详细讲讲吧... 目录拼接方式介绍性能对比测试代码测试结果源码分析golang的string类型是不可修改的,对于拼接字