本文介绍行人重识别项目,基于Paddle官方Metric Learning模型开发,修复Bug、优化代码并增加多个BackBone及模型导出脚本。使用Market-1501数据集,经解压、预处理后,用arcmargin loss训练,可微调提升性能,评估用Recall@Rank-1指标,未微调模型达96.65%,还涉及预测与模型导出。
☞☞☞AI 智能聊天, 问答助手, AI 智能搜索, 免费无限量使用 DeepSeek R1 模型☜☜☜

%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
%cd ~import osimport random
imgs = 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
%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.tar Resolving 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:67d Connecting 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 OK Length: 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]
%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%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%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_learning You are using Paddle compiled with TensorRT, but TensorRT dynamic library is not found. Ignore this if TensorRT is not needed.----------- Configuration Arguments ----------- batch_size: 256 embedding_size: 128 image_shape: 3,128,128 model: ResNet50_vd pretrained_model: pretrained_model/best_model_no_finetune use_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.1 W1118 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
%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%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_learning You are using Paddle compiled with TensorRT, but TensorRT dynamic library is not found. Ignore this if TensorRT is not needed.----------- Configuration Arguments ----------- embedding_size: 128 image_shape: 3,128,128 model: ResNet50_vd model_save_dir: save_inference_model pretrained_model: pretrained_model/best_model_no_finetune use_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.1 W1118 00:07:26.489738 8029 device_context.cc:346] device: 0, cuDNN Version: 7.6. Saving the inference model... Finish.
| 预训练模型 | arcmargin |
|---|---|
| 未微调 | 96.65% |
以上就是行人重识别:基于度量学习的行人重识别算法的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号