面包屑图标 当前位置: 首页
AI资讯
热点详情

行人重识别:基于度量学习的行人重识别算法

AI热点日报
AI热点日报时间:2025-07-21
热点解读

本文介绍行人重识别项目,基于Paddle最新Metric Learning模型开发,修复Bug、优化代码并增加多个BackBone及模型导出脚本。使用Market-1501数据集,

本文介绍行人重识别项目,基于Paddle最新Metric Learning模型开发,修复Bug、优化代码并增加多个BackBone及模型导出脚本。使用Market-1501数据集,经解压、预处理后,用arcmargin loss训练,可微调提升性能,评估用Recall@Rank-1指标,未微调模型达96.65%,还涉及预测与模型导出。

行人重识别:基于度量学习的行人重识别算法 - 游乐网

引入

行人重识别(Person Re-IDentification,简称Re-ID),也称行人再识别,是利用计算机视觉技术判断图像或者视频序列中是否存在特定行人的技术广泛被认为是一个图像检索的子问题。给定一个监控行人图像,检索跨设备下的该行人图像旨在弥补目前固定的摄像头的视觉局限,并可与行人检测/行人跟踪技术相结合,可广泛应用于智能视频监控、智能安保等领域具体任务为:一个区域有多个摄像头拍摄视频序列,ReID的要求对一个摄像头下感兴趣的行人,检索到该行人在其他摄像头下出现的所有图片

项目说明

本项目基于Paddle最新模型库中的Metric Learning模型开发修复了几个小Bug,清理和优化了代码增加了几个BackBone:GhostNet、MobileNetV3、ResNetVd增加模型导出脚本,导出模型可用于多目标追踪:DeepSort_Paddle项目

Metric Learning

Metric Learning即度量学习也叫作相似度学习将度量学习应用于图像领域,就可以用作图像的相似度评估行人重识别恰好可以通过评估两张行人图像的相似度来实现所以本次就使用Paddle最新模型库中的Metric Learning模型实现一个简单的行人重识别算法

数据集介绍

本次使用的数据集是经典的行人重识别数据集Market-1501Market-1501 数据集在清华大学校园中采集,夏天拍摄,在 2015 年构建并公开它包括由6个摄像头(其中5个高清摄像头和1个低清摄像头)拍摄到的 1501 个行人、32668 个检测到的行人矩形框每个行人至少由2个摄像头捕获到,并且在一个摄像头中可能具有多张图像训练集有 751 人,包含 12,936 张图像,平均每个人有 17.2 张训练数据;测试集有 750 人,包含 19,732 张图像,平均每个人有 26.3 张测试数据3368 张查询图像的行人检测矩形框是人工绘制的,而 gallery 中的行人检测矩形框则是使用DPM检测器检测得到的该数据集提供的固定数量的训练集和测试集均可以在single-shot或multi-shot测试设置下使用

解压数据集

In [ ]
%cd ~/work/metric_learning/data!tar -xf ~/data/data1884/Market-1501-v15.09.15.tar!mv Market-1501-v15.09.15 Market-1501
登录后复制        
/home/aistudio/work/metric_learning/data
登录后复制        

数据预处理

生成数据列表分割训练集和验证集In [ ]
%cd ~import osimport randomimgs = os.listdir('work/metric_learning/data/Market-1501/gt_bbox')imgs.sort()image_id = 1super_class_id = 1class_id = 1class_dict = {}for img in imgs:    if 'jpg' in img:        person_id = img[:4]        if person_id not in class_dict:            class_dict[person_id] = class_id            class_id += 1total = []for img in imgs:    if 'jpg' in img:        person_id = img[:4]        path = 'gt_bbox/'+img        line = '%s %s %s %s\n' % (image_id, class_dict[person_id], super_class_id, path)        image_id += 1        total.append(line)# random.shuffle(total)train = total[:-1014]dev = total[-1014:]with open('work/metric_learning/data/Market-1501/train.txt', 'w', encoding='UTF-8') as f:    f.write('image_id class_id super_class_id path\n')    for line in train:        f.write(line)    with open('work/metric_learning/data/Market-1501/test.txt', 'w', encoding='UTF-8') as f:    f.write('image_id class_id super_class_id path\n')    for line in dev:        f.write(line)
登录后复制        
/home/aistudio
登录后复制        

下载预训练模型

这里使用ResNet50_vd做演示可根据需要选择其他更合适的BackBone其他预训练模型可在PaddleClas套件的模型库中找到In [ ]
%cd ~/work/metric_learning/pretrained_model!wget https://paddle-imagenet-models-name.bj.bcebos.com/ResNet50_vd_ssld_v2_pretrained.tar!tar -xf ResNet50_vd_ssld_v2_pretrained.tar
登录后复制        
/home/aistudio/work/metric_learning/pretrained_model--2020-11-18 00:03:50--  https://paddle-imagenet-models-name.bj.bcebos.com/ResNet50_vd_ssld_v2_pretrained.tarResolving paddle-imagenet-models-name.bj.bcebos.com (paddle-imagenet-models-name.bj.bcebos.com)... 182.61.200.195, 182.61.200.229, 2409:8c00:6c21:10ad:0:ff:b00e:67dConnecting to paddle-imagenet-models-name.bj.bcebos.com (paddle-imagenet-models-name.bj.bcebos.com)|182.61.200.195|:443... connected.HTTP request sent, awaiting response... 200 OKLength: 95165219 (91M) [application/x-tar]Saving to: ‘ResNet50_vd_ssld_v2_pretrained.tar’ResNet50_vd_ssld_v2 100%[===================>]  90.76M  48.0MB/s    in 1.9s    2020-11-18 00:03:52 (48.0 MB/s) - ‘ResNet50_vd_ssld_v2_pretrained.tar’ saved [95165219/95165219]
登录后复制        

模型训练

使用softmax loss或者arcmargin loss进行模型训练In [ ]
%cd ~/work/metric_learning!python train_elem.py \    --model ResNet50_vd \    --embedding_size 128 \    --train_batch_size 256 \    --test_batch_size 256 \    --image_shape 3,128,128 \    --class_dim 1421 \    --lr 0.1 \    --lr_strategy piecewise_decay \    --lr_steps 5000,7000,9000 \    --total_iter_num 10000 \    --display_iter_step 10 \    --test_iter_step 500 \    --save_iter_step 500 \    --use_gpu True \    --pretrained_model pretrained_model/ResNet50_vd_ssld_v2_pretrained \    --model_save_dir save_elem_model \    --loss_name arcmargin \    --arc_scale 80.0 \    --arc_margin 0.15 \    --arc_easy_margin False
登录后复制    

模型微调

上述训练完成后还可对模型进行微调,进一步提升性能In [ ]
%cd ~/work/metric_learning!python train_pair.py \    --model ResNet50_vd \    --embedding_size 128 \    --train_batch_size 64 \    --test_batch_size 64 \    --image_shape 3,128,128 \    --class_dim 1421 \    --lr 0.0001 \    --lr_strategy piecewise_decay \    --lr_steps 3000,6000,9000 \    --total_iter_num 10000 \    --display_iter_step 10 \    --test_iter_step 500 \    --save_iter_step 500 \    --use_gpu True \    --pretrained_model save_elem_model/ResNet50_vd/10000 \    --model_save_dir save_pair_model \    --loss_name eml \    --samples_each_class 4 \    --margin 0.1 \    --npairs_reg_lambda 0.01
登录后复制    

模型评估

对模型的检索效果进行评估,这里使用Recall@Rank-1作为评估指标In [5]
%cd ~/work/metric_learning# arcmargin未微调模型!python eval.py \    --model ResNet50_vd \    --embedding_size 128 \    --batch_size 256 \    --image_shape 3,128,128 \    --use_gpu True \    --pretrained_model pretrained_model/best_model_no_finetune
登录后复制        
/home/aistudio/work/metric_learningYou are using Paddle compiled with TensorRT, but TensorRT dynamic library is not found. Ignore this if TensorRT is not needed.-----------  Configuration Arguments -----------batch_size: 256embedding_size: 128image_shape: 3,128,128model: ResNet50_vdpretrained_model: pretrained_model/best_model_no_finetuneuse_gpu: 1------------------------------------------------W1118 00:06:56.248965  7755 device_context.cc:338] Please NOTE: device: 0, CUDA Capability: 70, Driver API Version: 10.1, Runtime API Version: 10.1W1118 00:06:56.254372  7755 device_context.cc:346] device: 0, cuDNN Version: 7.6.val dataset size: 80[2020-11-18 00:07:01] testbatch 0, time 0.14 sec[2020-11-18 00:07:05] End test 1014, test_recall 0.96647
登录后复制        

模型预测

使用模型输出预测图像的特征编码In [2]
%cd ~/work/metric_learning!python infer.py \    --model ResNet50_vd \    --embedding_size 128 \    --batch_size 1 \    --image_shape 3,128,128 \    --use_gpu True \    --pretrained_model pretrained_model/best_model_no_finetune
登录后复制    

模型导出

In [6]
%cd ~/work/metric_learning!python export_model.py \    --model ResNet50_vd \    --embedding_size 128 \    --image_shape 3,128,128 \    --use_gpu True \    --pretrained_model=pretrained_model/best_model_no_finetune \    --model_save_dir=save_inference_model
登录后复制        
/home/aistudio/work/metric_learningYou are using Paddle compiled with TensorRT, but TensorRT dynamic library is not found. Ignore this if TensorRT is not needed.-----------  Configuration Arguments -----------embedding_size: 128image_shape: 3,128,128model: ResNet50_vdmodel_save_dir: save_inference_modelpretrained_model: pretrained_model/best_model_no_finetuneuse_gpu: 1------------------------------------------------W1118 00:07:26.484359  8029 device_context.cc:338] Please NOTE: device: 0, CUDA Capability: 70, Driver API Version: 10.1, Runtime API Version: 10.1W1118 00:07:26.489738  8029 device_context.cc:346] device: 0, cuDNN Version: 7.6.Saving the inference model...Finish.
登录后复制        

总结

由于微调训练速度较慢,暂未有训练完成的模型训练完成的模型效果(Recall@Rank-1):
热点追踪提示词
你是一名 AI 行业编辑,请围绕下面这条热点输出一份资讯解读:
热点:行人重识别:基于度量学习的行人重识别算法要求:
1. 先用一句话解释这条热点在讲什么
2. 再总结它为什么重要
3. 说明会影响哪些 AI 产品或内容方向
4. 最后给出 3 个适合资讯站使用的标题
来源:https://www.php.cn/faq/1419475.html
python ai 算法 bug

游乐网为非赢利性网站,所展示的游戏/软件/文章内容均来自于互联网或第三方用户上传分享,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系youleyoucom@outlook.com。

相关热点
AI热点2026-07-03 18:36
模型上下文协议(MCP)与API对比入门指南

AI领域近期有一个术语热度迅速攀升——MCP。如果您尚未理解其具体含义,以及它与传统API之间的本质区别,那么这篇文章将帮助您系统梳理这些内容。 首先明确几个核心判断:MCP(Model Context Protocol,模型上下文协议)并非又一个花哨的技术缩写,而是一个正在深刻改变AI工具集成方式

AI热点2026-07-03 18:36
Sophos高通合作开发AI深度学习安全新PC

Sophos计划将安全产品InterceptX与高通骁龙计算平台深度整合,利用深度学习AI和反勒索软件功能阻断网络安全威胁。双方结合骁龙平台的5G连接与AI加速能力,打造始终连接的PC安全环境,提升端点防护水平。产品预计2021年下半年上市。

AI热点2026-07-03 18:35
研华EI-52边缘智能系统搭载第11代酷睿驱动5G与AI应用

在边缘计算领域,今年明显呈现出加速发展的趋势。市场上涌现出众多解决方案,但真正能够实现“开箱即用”、且面向5G与AI场景的紧凑型系统并不多见。正因如此,研华科技最新推出的EI-52边缘智能系统,成为值得关注的重要信号——它将硬件、软件与连接能力高度整合,直击部署效率这一核心痛点。 该产品的定位十分清

AI热点2026-07-03 18:35
中国企业进入IEC最高决策机构的科技价值启示

提到中国科技自立自强,公众最先想到的往往是人工智能、自动驾驶、云计算等大国重器,以及冲锋在前沿的IT企业与互联网科技公司。 但深入观察会发现,谷歌、Facebook、亚马逊、BAT等巨头也在积极布局物联网,尤其是与智能家居深度融合。当前,单纯科普前沿技术已不足以驱动变革,关键在于让广大用户真正接触、

延伸阅读