资源简介
该代码实现了对行人重识别,准确率达到88%左右,最好的情况的下可以达到90%。

代码片段和文件信息
import argparse
import scipy.io
import torch
import numpy as np
import time
import os
from torchvision import datasets models transforms
import matplotlib
matplotlib.use(‘agg‘)
import matplotlib.pyplot as plt
#######################################################################
# Evaluate
parser = argparse.ArgumentParser(description=‘Demo‘)
parser.add_argument(‘--query_index‘ default=777 type=int help=‘test_image_index‘)
parser.add_argument(‘--test_dir‘default=‘../Market/pytorch‘type=str help=‘./test_data‘)
opts = parser.parse_args()
data_dir = opts.test_dir
image_datasets = {x: datasets.ImageFolder( os.path.join(data_dirx) ) for x in [‘gallery‘‘query‘]}
#####################################################################
#Show result
def imshow(path title=None):
“““Imshow for Tensor.“““
im = plt.imread(path)
plt.imshow(im)
if title is not None:
plt.title(title)
plt.pause(0.001) # pause a bit so that plots are updated
######################################################################
result = scipy.io.loadmat(‘pytorch_result.mat‘)
query_feature = torch.FloatTensor(result[‘query_f‘])
query_cam = result[‘query_cam‘][0]
query_label = result[‘query_label‘][0]
gallery_feature = torch.FloatTensor(result[‘gallery_f‘])
gallery_cam = result[‘gallery_cam‘][0]
gallery_label = result[‘gallery_label‘][0]
multi = os.path.isfile(‘multi_query.mat‘)
if multi:
m_result = scipy.io.loadmat(‘multi_query.mat‘)
mquery_feature = torch.FloatTensor(m_result[‘mquery_f‘])
mquery_cam = m_result[‘mquery_cam‘][0]
mquery_label = m_result[‘mquery_label‘][0]
mquery_feature = mquery_feature.cuda()
query_feature = query_feature.cuda()
gallery_feature = gallery_feature.cuda()
#######################################################################
# sort the images
def sort_img(qf ql qc gf gl gc):
query = qf.view(-11)
# print(query.shape)
score = torch.mm(gfquery)
score = score.squeeze(1).cpu()
score = score.numpy()
# predict index
index = np.argsort(score) #from small to large
index = index[::-1]
# index = index[0:2000]
# good index
query_index = np.argwhere(gl==ql)
#same camera
camera_index = np.argwhere(gc==qc)
good_index = np.setdiff1d(query_index camera_index assume_unique=True)
junk_index1 = np.argwhere(gl==-1)
junk_index2 = np.intersect1d(query_index camera_index)
junk_index = np.append(junk_index2 junk_index1)
mask = np.in1d(index junk_index invert=True)
index = index[mask]
return index
i = opts.query_index
index = sort_img(query_feature[i]query_label[i]query_cam[i]gallery_featuregallery_labelgallery_cam)
########################################################################
# Visualize the rank result
query_path label = image_datasets[‘query‘].imgs[opts.query_index]
print(query_path)
print(‘Top 10 images are as follow:‘)
try: # Visualize Ranking Result
# Graphical User Interface is needed
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2018-08-28 04:18 Person_reID_ba
文件 1070 2018-08-28 04:18 Person_reID_ba
文件 7494 2018-08-28 04:18 Person_reID_ba
文件 218585 2018-08-28 04:18 Person_reID_ba
文件 3578 2018-08-28 04:18 Person_reID_ba
文件 3424 2018-08-28 04:18 Person_reID_ba
文件 3729 2018-08-28 04:18 Person_reID_ba
文件 2735 2018-08-28 04:18 Person_reID_ba
文件 6743 2018-08-28 04:18 Person_reID_ba
目录 0 2018-08-28 04:18 Person_reID_ba
文件 1 2018-08-28 04:18 Person_reID_ba
文件 3554 2018-08-28 04:18 Person_reID_ba
文件 4034 2018-08-28 04:18 Person_reID_ba
文件 1926 2018-08-28 04:18 Person_reID_ba
文件 4199 2018-08-28 04:18 Person_reID_ba
文件 6850 2018-08-28 04:18 Person_reID_ba
文件 53483 2018-08-28 04:18 Person_reID_ba
文件 12512 2018-08-28 04:18 Person_reID_ba
相关资源
- 二级考试python试题12套(包括选择题和
- pywin32_python3.6_64位
- python+ selenium教程
- PycURL(Windows7/Win32)Python2.7安装包 P
- 英文原版-Scientific Computing with Python
- 7.图像风格迁移 基于深度学习 pyt
- 基于Python的学生管理系统
- A Byte of Python(简明Python教程)(第
- Python实例174946
- Python 人脸识别
- Python 人事管理系统
- 基于python-flask的个人博客系统
- 计算机视觉应用开发流程
- python 调用sftp断点续传文件
- python socket游戏
- 基于Python爬虫爬取天气预报信息
- python函数编程和讲解
- Python开发的个人博客
- 基于python的三层神经网络模型搭建
- python实现自动操作windows应用
- python人脸识别(opencv)
- python 绘图(方形、线条、圆形)
- python疫情卡UN管控
- python 连连看小游戏源码
- 基于PyQt5的视频播放器设计
- 一个简单的python爬虫
- csv文件行列转换python实现代码
- Python操作Mysql教程手册
- Python Machine Learning Case Studies
- python获取硬件信息
评论
共有 条评论