dgs.models.dataset.dataset.BaseDataset¶
- class dgs.models.dataset.dataset.BaseDataset(*args: Any, **kwargs: Any)[source]¶
Base class for custom datasets.
Every dataset is based around the
State
object, which is just a fancy dict containing all the data of the current step. But there are two different approaches when thinking about “one sample”. They have different use-cases and therefore different advantages and disadvantages.Using the Bounding Box as Index¶
One sample of the dataset (one
__getitem__()
call) contains the data of one single bounding-box. Therefore, a batch of this dataset containsB
bounding-boxes, with the same amount of filepaths, images, key-points, … . The bounding-boxes can be sampled randomly from the dataset, because there is no time-based information. This method can be used for generating and training the visual Re-ID embeddings, because the model does not care when or in which order the bounding-boxes representing the Person-ID (class labels) are perceived.A dataset with this kind of structure will always return a single
State
containing the data.Using the Image ID as Index¶
One sample of the dataset contains the data of all people / bounding-boxes detected on one single image. Because now we can be sure that all detections of this image are in the current sample, it is possible to move through the dataset in a frame-by-frame manner, keeping time-based information. This is especially useful when working with tracks because the tracks of the current frame depend on the tracks of the previous frame(s), at least in most scenarios.
Due to the time-dependencies, it is not (really) possible to use batches without precomputing part of the tracks, which might result in a worse performance during training. During evaluation, it is possible to use the ground-truth track-information, even though this might change the results of the model, and it has to be shown how grave this influences the results.
When batches are used, the batch-size will vary because every image can have a different number of detections. Every image has a specific number of detections
N
, ranging from zero to an arbitrary number. This means that with a batch size ofB
, we obtainB
original images, but the length of the resultingState
will most likely be larger. Constant batches are possible when trimming overflowing detections, but this is not recommended. The other option is to keep the batches with differing sizes. TheDataLoader
loads a fixed batch of images, the__getitem__()
call of the Dataset then computes the resulting detections and returns those as a list ofState
‘s.Params¶
- dataset_path (FilePath):
Path to the directory of the dataset. The value has to either be a local project path, or a valid absolute path.
- data_path (FilePath):
The path to the file containing the data for this dataset. Either from within the
dataset_path
directory, or as absolute path. If you want to combine multiple files to a single (concatenated) dataset, check out the functionget_concatenated_dataset()
or thepaths
parameter.
Optional Params¶
- force_img_reshape (bool, optional):
Whether to accept that images in one folder might have different shapes. Default
DEF_VAL.dataset.force_img_reshape
.- image_mode (str, optional):
Only applicable if
force_img_reshape
is True. The cropping mode used for loading the full images when callingget_image_crops()
. Value has to be inCustomToAspect.modes`
. DefaultDEF_VAL.images.image_mode
.- image_size (tuple[int, int], optional):
Only applicable if
force_img_reshape
is True. The size that the original images should have. DefaultDEF_VAL.images.image_size
.- crops_folder (FilePath, optional):
A path (global, project local, or dataset local), containing the previously cropped images. The structure is dataset-dependent, and might not be necessary for some datasets. Default is not set, and the crops are generated live. Default
DEF_VAL.dataset.crops_folder
.- crop_mode (str, optional):
The mode for image cropping used when calling
get_image_crops()
. Value has to be inCustomToAspect.modes
. DefaultDEF_VAL.images.crop_mode
.- crop_size (tuple[int, int], optional):
The size, the resized image should have. Default
DEF_VAL.images.crop_size
.- paths (list[FilePath], optional):
A list of file paths to concatenate into a single dataset using
get_concatenated_dataset()
. Will be ignored by the single dataset. Can contain ‘*’ and similar wildcards used inglob.glob()
to search for multiple files matching a pattern.
Additional Params for the DataLoader¶
- batch_size (int, optional):
The batch size to use while creating the DataLoader for this Dataset. Default
DEF_VAL.dataloader.batch_size
.- drop_last (bool, optional):
Whether to drop the last batch if its size is unequal to the target batch size. Default
DEF_VAL.dataloader.drop_last
.- shuffle (bool, optional):
Whether to shuffle the dataset. Default
DEF_VAL.dataloader.shuffle
.- workers (int, optional):
The number of workers for multi-device data-loading. Not fully supported! Therefore, default 0, no multi-device. Default
DEF_VAL.dataloader.workers
.- collate_fn (bool, optional):
Which collate function to use, when collating the States for the DataLoader. Can be
None
or one of"lists"
,"states"
, or"history"
. DefaultDEF_VAL.dataloader.collate_fn
.
Default Values¶
batch_size: 16
drop_last: False
shuffle: False
workers: 0
collate_fn: None
crops_folder:
force_img_reshape: False
pt21: {‘check_img_sizes’: False, ‘load_img_crops’: True}
kprcnn: {‘score_threshold’: 0.3, ‘iou_threshold’: 0.6}
MOT: {‘space_around_delimiters’: False, ‘file_separator’: ‘,\s?’, ‘seqinfo_path’: None, ‘crop_key’: ‘Crops’}
- __init__(config: dict[str, any], path: list[str]) None [source]¶
Methods
arbitrary_to_ds
(a, idx)Given an index, convert arbitrary data into a
State
or a list of States.configure_torch_module
(module[, train])Set compute mode and send model to the device or multiple parallel devices if applicable.
get_image_crops
(ds)Add the image crops and local key-points to a given state.
get_path_in_dataset
(path)Given an arbitrary file- or directory-path, return its absolute path.
Terminate this module and all of its submodules.
Given one single image, with its corresponding bounding boxes and key-points, obtain a cropped image for every bounding box with localized key-points.
Given an image, bboxes, and key-points, resize them with custom modes.
validate_params
(validations[, attrib_name])Given per key validations, validate this module's parameters.
Attributes
Get the device of this module.
Get whether this module is set to training-mode.
Get the name of the module.
Get the name of the module.
Get the escaped name of the module usable in filepaths by replacing spaces and underscores.
Get the (floating point) precision used in multiple parts of this module.
Arbitrary data, which will be converted using
self.arbitrary_to_ds()
The base path to the dataset.