两张人像对比是否是同一人- 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

相关文章

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类型是不可修改的,对于拼接字

MySQL表锁、页面锁和行锁的作用及其优缺点对比分析

《MySQL表锁、页面锁和行锁的作用及其优缺点对比分析》MySQL中的表锁、页面锁和行锁各有特点,适用于不同的场景,表锁锁定整个表,适用于批量操作和MyISAM存储引擎,页面锁锁定数据页,适用于旧版本... 目录1. 表锁(Table Lock)2. 页面锁(Page Lock)3. 行锁(Row Lock

Python使用Pandas对比两列数据取最大值的五种方法

《Python使用Pandas对比两列数据取最大值的五种方法》本文主要介绍使用Pandas对比两列数据取最大值的五种方法,包括使用max方法、apply方法结合lambda函数、函数、clip方法、w... 目录引言一、使用max方法二、使用apply方法结合lambda函数三、使用np.maximum函数

linux下多个硬盘划分到同一挂载点问题

《linux下多个硬盘划分到同一挂载点问题》在Linux系统中,将多个硬盘划分到同一挂载点需要通过逻辑卷管理(LVM)来实现,首先,需要将物理存储设备(如硬盘分区)创建为物理卷,然后,将这些物理卷组成... 目录linux下多个硬盘划分到同一挂载点需要明确的几个概念硬盘插上默认的是非lvm总结Linux下多

vue解决子组件样式覆盖问题scoped deep

《vue解决子组件样式覆盖问题scopeddeep》文章主要介绍了在Vue项目中处理全局样式和局部样式的方法,包括使用scoped属性和深度选择器(/deep/)来覆盖子组件的样式,作者建议所有组件... 目录前言scoped分析deep分析使用总结所有组件必须加scoped父组件覆盖子组件使用deep前言

锐捷和腾达哪个好? 两个品牌路由器对比分析

《锐捷和腾达哪个好?两个品牌路由器对比分析》在选择路由器时,Tenda和锐捷都是备受关注的品牌,各自有独特的产品特点和市场定位,选择哪个品牌的路由器更合适,实际上取决于你的具体需求和使用场景,我们从... 在选购路由器时,锐捷和腾达都是市场上备受关注的品牌,但它们的定位和特点却有所不同。锐捷更偏向企业级和专