本文主要是介绍行人重识别reid数据集,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
有需要的人,请在评论区留下你的邮箱。
本人,双非学校小硕。研究方向行人重识别。收集了一些常用数据集。
Market-1501-v15.09.15
dukemtmc-reid
顺便附上一个根据相机id划分数据集的代码
import os
import shutil
import os.path as osp
import numpy as np
import glob
import re
from collections import defaultdictfrom tqdm import tqdmdef _process_dir(dir_path, relabel=False):img_paths = glob.glob(osp.join(dir_path, '*.jpg')) # 把此文件夹下的以jpg结尾的文件路径获取pattern = re.compile(r'([-\d]+)_c(\d)')# 将源pid构建一个映射,得到新的对应标签pid_container = set() # 定义集合。重复数据会被删除,同时会排序for img_path in img_paths:pid, _ = map(int, pattern.search(img_path).groups()) # 只有两段都是数字。map映射if pid == -1: continue # 有一些辣鸡数据pid_container.add(pid)pid2label = {pid: label for label, pid in enumerate(pid_container)}# 将数据打包成元组,进行储存dataset = []for img_path in img_paths:pid, camid = map(int, pattern.search(img_path).groups())if pid == -1: continue#assert 0 <= pid <= 1501assert 1 <= camid <= 8camid -= 1if relabel: pid = pid2label[pid]dataset.append((img_path, pid, camid))num_pids = len(pid_container)num_imgs = len(dataset)return dataset, num_pids, num_imgs # dataset打包好的数据if __name__ == '__main__':img_dir = os.path.join('cam_0_ID')img_dir1 = os.path.join('cam_1_ID')img_dir2 = os.path.join('cam_2_ID')img_dir3 = os.path.join('cam_3_ID')img_dir4 = os.path.join('cam_4_ID')img_dir5 = os.path.join('cam_5_ID')img_dir6 = os.path.join('cam_6_ID')img_dir7 = os.path.join('cam_7_ID')img_names=os.listdir(img_dir) #所有文件名img_set,_,_=_process_dir(img_dir)camid_to_img=defaultdict(list)for i in img_set:# print(i)camid_to_img[i[2]].append(i[0])#print(camid_to_img[1])#print(len(camid_to_img.keys())) ==6for i in tqdm(range(len(camid_to_img.keys()))):os.mkdir(os.path.join('cam_{}_ID').format(i))target_file=os.path.join('cam_{}_ID').format(i)for j in range(len(camid_to_img[i])):img_name = '\\'.join(camid_to_img[i][j].split('\\')[1:]) #文件名#print(img_name)if img_name in img_names:target_path = os.path.join(target_file, img_name)src_path = os.path.join(img_dir,img_name)shutil.copy(src_path, target_path)
MSMT17(最初的版本)(建议做科研的话,使用最初的版本)
因为根据个人实验经历来看,这个版本的评估才是准确的。后面的更改的后的V1或者V2版本有误差。
dataset的代码:
from __future__ import print_function, absolute_import
import os.path as osp
import tarfileimport glob
import re
import urllib
import zipfilefrom ..utils.osutils import mkdir_if_missing
from ..utils.serialization import write_jsondef _pluck_msmt(list_file, subdir, pattern=re.compile(r'([-\d]+)_([-\d]+)_([-\d]+)')):with open(list_file, 'r') as f:lines = f.readlines()ret = []pids = []for line in lines:line = line.strip()fname = line.split(' ')[0]pid, _, cam = map(int, pattern.search(osp.basename(fname)).groups())if pid not in pids:pids.append(pid)ret.append((osp.join(subdir,fname), pid, cam))return ret, pidsclass Dataset_MSMT(object):def __init__(self, root):self.root = rootself.train, self.val, self.trainval = [], [], []self.query, self.gallery = [], []self.num_train_ids, self.num_val_ids, self.num_trainval_ids = 0, 0, 0@propertydef images_dir(self):return osp.join(self.root, 'MSMT17_V1')def load(self, verbose=True):exdir = osp.join(self.root, 'MSMT17_V1')self.train, train_pids = _pluck_msmt(osp.join(exdir, 'list_train.txt'), 'train')self.val, val_pids = _pluck_msmt(osp.join(exdir, 'list_val.txt'), 'train')self.train = self.train + self.valself.query, query_pids = _pluck_msmt(osp.join(exdir, 'list_query.txt'), 'test')self.gallery, gallery_pids = _pluck_msmt(osp.join(exdir, 'list_gallery.txt'), 'test')self.num_train_pids = len(list(set(train_pids).union(set(val_pids))))if verbose:print(self.__class__.__name__, "dataset loaded")print(" subset | # ids | # images")print(" ---------------------------")print(" train | {:5d} | {:8d}".format(self.num_train_pids, len(self.train)))print(" query | {:5d} | {:8d}".format(len(query_pids), len(self.query)))print(" gallery | {:5d} | {:8d}".format(len(gallery_pids), len(self.gallery)))class MSMT17(Dataset_MSMT):def __init__(self, root, split_id=0, download=True):super(MSMT17, self).__init__(root)if download:self.download()self.load()def download(self):import reimport hashlibimport shutilfrom glob import globfrom zipfile import ZipFileraw_dir = osp.join(self.root)mkdir_if_missing(raw_dir)# Download the raw zip filefpath = osp.join(raw_dir, 'MSMT17_V1')if osp.isdir(fpath):print("Using downloaded file: " + fpath)else:raise RuntimeError("Please download the dataset manually to {}".format(fpath))
MSMT17_V1(重命名图片版本)
之后有研究者为了与market1501统一起来,将图片格式改为与其一致。
需要的同学,记得点个赞。并留下你的邮箱。
这篇关于行人重识别reid数据集的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!