时间:2025-07-21 作者:游乐小编
本文介绍行人重识别项目,基于Paddle最新Metric Learning模型开发,修复Bug、优化代码并增加多个BackBone及模型导出脚本。使用Market-1501数据集,经解压、预处理后,用arcmargin loss训练,可微调提升性能,评估用Recall@Rank-1指标,未微调模型达96.65%,还涉及预测与模型导出。
%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 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登录后复制
%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]登录后复制
%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_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登录后复制
%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_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.登录后复制
2021-11-05 11:52
手游攻略2021-11-19 18:38
手游攻略2021-10-31 23:18
手游攻略2022-06-03 14:46
游戏资讯2025-06-28 12:37
单机攻略