deep-person-reid/torchreid/data/datasets/__init__.py

118 lines
3.4 KiB
Python
Raw Normal View History

2019-12-01 10:35:44 +08:00
from __future__ import print_function, absolute_import
2019-03-21 20:59:54 +08:00
2019-12-01 11:31:32 +08:00
from .image import (
GRID, PRID, CUHK01, CUHK02, CUHK03, MSMT17, VIPeR, SenseReID, Market1501,
DukeMTMCreID, iLIDS
)
from .video import PRID2011, Mars, DukeMTMCVidReID, iLIDSVID
2019-12-01 10:35:44 +08:00
from .dataset import Dataset, ImageDataset, VideoDataset
2019-03-21 20:59:54 +08:00
__image_datasets = {
'market1501': Market1501,
'cuhk03': CUHK03,
'dukemtmcreid': DukeMTMCreID,
'msmt17': MSMT17,
'viper': VIPeR,
'grid': GRID,
'cuhk01': CUHK01,
'ilids': iLIDS,
'sensereid': SenseReID,
2019-08-30 00:05:29 +08:00
'prid': PRID,
'cuhk02': CUHK02
2019-03-21 20:59:54 +08:00
}
__video_datasets = {
'mars': Mars,
'ilidsvid': iLIDSVID,
'prid2011': PRID2011,
'dukemtmcvidreid': DukeMTMCVidReID
}
def init_image_dataset(name, **kwargs):
2019-03-24 07:09:39 +08:00
"""Initializes an image dataset."""
2019-03-21 20:59:54 +08:00
avai_datasets = list(__image_datasets.keys())
if name not in avai_datasets:
2019-12-01 10:35:44 +08:00
raise ValueError(
'Invalid dataset name. Received "{}", '
'but expected to be one of {}'.format(name, avai_datasets)
)
2019-03-21 20:59:54 +08:00
return __image_datasets[name](**kwargs)
def init_video_dataset(name, **kwargs):
2019-03-24 07:09:39 +08:00
"""Initializes a video dataset."""
2019-03-21 20:59:54 +08:00
avai_datasets = list(__video_datasets.keys())
if name not in avai_datasets:
2019-12-01 10:35:44 +08:00
raise ValueError(
'Invalid dataset name. Received "{}", '
'but expected to be one of {}'.format(name, avai_datasets)
)
2019-03-22 01:28:14 +08:00
return __video_datasets[name](**kwargs)
2019-05-25 00:13:30 +08:00
def register_image_dataset(name, dataset):
2019-03-25 07:33:54 +08:00
"""Registers a new image dataset.
2019-03-24 07:09:39 +08:00
Args:
2019-03-25 07:33:54 +08:00
name (str): key corresponding to the new dataset.
2019-05-25 00:13:30 +08:00
dataset (Dataset): the new dataset class.
2019-03-24 07:09:39 +08:00
Examples::
import torchreid
2019-03-25 07:33:54 +08:00
import NewDataset
torchreid.data.register_image_dataset('new_dataset', NewDataset)
2019-03-24 07:09:39 +08:00
# single dataset case
datamanager = torchreid.data.ImageDataManager(
root='reid-data',
2019-03-25 07:33:54 +08:00
sources='new_dataset'
2019-03-24 07:09:39 +08:00
)
# multiple dataset case
datamanager = torchreid.data.ImageDataManager(
root='reid-data',
2019-03-25 07:33:54 +08:00
sources=['new_dataset', 'dukemtmcreid']
2019-03-24 07:09:39 +08:00
)
"""
2019-05-25 00:13:30 +08:00
global __image_datasets
2019-03-22 01:28:14 +08:00
curr_datasets = list(__image_datasets.keys())
if name in curr_datasets:
2019-12-01 10:35:44 +08:00
raise ValueError(
'The given name already exists, please choose '
'another name excluding {}'.format(curr_datasets)
)
2019-05-25 00:13:30 +08:00
__image_datasets[name] = dataset
2019-03-22 01:28:14 +08:00
2019-05-25 00:13:30 +08:00
def register_video_dataset(name, dataset):
2019-03-25 07:33:54 +08:00
"""Registers a new video dataset.
2019-03-24 07:09:39 +08:00
Args:
2019-03-25 07:33:54 +08:00
name (str): key corresponding to the new dataset.
2019-05-25 00:13:30 +08:00
dataset (Dataset): the new dataset class.
2019-03-24 07:09:39 +08:00
Examples::
import torchreid
2019-03-25 07:33:54 +08:00
import NewDataset
torchreid.data.register_video_dataset('new_dataset', NewDataset)
2019-03-24 07:09:39 +08:00
# single dataset case
datamanager = torchreid.data.VideoDataManager(
root='reid-data',
2019-03-25 07:33:54 +08:00
sources='new_dataset'
2019-03-24 07:09:39 +08:00
)
# multiple dataset case
datamanager = torchreid.data.VideoDataManager(
root='reid-data',
2019-03-25 07:33:54 +08:00
sources=['new_dataset', 'ilidsvid']
2019-03-24 07:09:39 +08:00
)
"""
2019-05-25 00:13:30 +08:00
global __video_datasets
2019-03-22 01:28:14 +08:00
curr_datasets = list(__video_datasets.keys())
if name in curr_datasets:
2019-12-01 10:35:44 +08:00
raise ValueError(
'The given name already exists, please choose '
'another name excluding {}'.format(curr_datasets)
)
2019-05-25 00:13:30 +08:00
__video_datasets[name] = dataset