Custom Dataset¶
Module containing the custom torch.utils.data.Dataset classes used in this package.
- class master_thesis.dataset.MasterThesisDataset(bgs_dataset_meta, masks_dataset_meta, bgs_simulator, masks_simulator, split, **kwargs)¶
Bases:
torch.utils.data.dataset.Dataset
Implementation of the custom dataset class used in the package.
Both the background and the mask will be either extracted from a real sequence or simulated using single real frames after applying affine transformations. The CLI arguments
--p-simulator-bgs
and-p-simulator-masks
define the probability that a certain item data item has been obtained using the simulation mode.If
self.kwargs['frames_n']
is set to -1, the entire sequence associated with the desired item is returned.- bgs_dataset¶
Instance of the dataset returning background images.
- masks_dataset¶
Instance of the dataset returning binary masks.
- split¶
Split of the dataset.
- kwargs¶
Dictionary containing the CLI arguments used in the execution.
- FILL_COLOR = tensor([0.4850, 0.4560, 0.4060])¶
- __getitem__(item)¶
Returns an item from the dataset, where an item is composed by a background image, its masked version, the binary mask and some auxiliary information.
- Parameters
item – Index of the data item to return.
- Returns
Tuple of the form
((x, m), y, (bg_name, bg_indexes, use_simulator_bgs, use_simulator_masks, 0, gt_movement, m_movement))
, where:x: masked sequence.
m: binary shape used to mask
y
.y: original background sequence before being masked.
bg_name: name of the sequence used in the original dataset.
bg_indexes: string
use_simulator_bgs: boolean indicating if the background sequence has been obtained by applying random transformations to a frame.
- use_simulator_masks: boolean indicating if the masks
sequence has been obtained by applying random transformations to a mask.
gt_movement: tensor containing
- __len__() int ¶
Returns the length of the dataset. If the argument frames_n is set to -1, the length is the number of background videos available. If set to another value, the length is the sum of all the sequences frames.
- Returns
Number of dataset items using the given configuration.
- class master_thesis.dataset.MasterThesisContentProvider(dataset_meta, bgs_movement_min_height, movement_simulator, **kwargs)¶
Bases:
torch.utils.data.dataset.Dataset
- __getitem__(frame_index)¶
Returns both the background and the mask associated with index
frame_item
.- Parameters
frame_index – frame index between 0 and
self.__len__()
.- Returns
tensor of size (C,H,W) containing a GT image quantized between [0,1] or None. torch.FloatTensor: tensor of size (C,H,W) containing a mask image quantized between [0,1] or None. str: name of the sequence.
- Return type
torch.FloatTensor
- get_items(frames_indexes)¶
Returns the backgrounds and the masks at indexes
frames_indexes
.- Parameters
frames_indexes – list of indexes of the frames that should be
returned. –
- Returns
Tuple of two tensors containing the backgrounds and the masks, respectively. The tensor containing the backgrounds has size (C,F, H,W), while the tensor containing the masks is (1,F,H,W).
- __len__()¶
Returns the sum of the frames of all sequences.
- Returns
Length of the dataset, given by the sum of the frames of all sequences.
- get_sequence(sequence_index)¶
Returns the sequence with index
sequence_index
.- Parameters
sequence_index – sequence index between 0 and
self.len_sequences() –
- Returns
Tuple containing the backgrounds, masks, names
- len_sequences()¶
Return the number of different sequences.
- get_patch(frame_index, frames_n, use_movement_simulator)¶
- get_patch_random(frames_n, movement_simulator)¶