vis4d.data.reference

Reference View Sampling.

These Classes sample reference views from a dataset that contains videos. This is usually used when a model needs multiple samples of a video during training.

Functions

sort_key_first(cur_sample, ref_data)

Sort views as key first.

sort_temporal(cur_sample, ref_data)

Sort views temporally.

Classes

MultiViewDataset(dataset, sampler[, ...])

Dataset that samples reference views from a video dataset.

ReferenceViewSampler(num_ref_samples)

Base reference view sampler.

SequentialViewSampler(num_ref_samples)

Sequential View Sampler.

UniformViewSampler(scope, num_ref_samples)

View Sampler that chooses reference views uniform at random.

class MultiViewDataset(dataset, sampler, sort_fn=<function sort_key_first>, num_retry=3, match_key='boxes2d_track_ids', skip_nomatch_samples=False)[source]

Dataset that samples reference views from a video dataset.

Creates an instance of the class.

Parameters:
  • dataset (Dataset) – Video dataset to sample from.

  • sampler (ReferenceViewSampler) – Sampler that samples reference views.

  • sort_fn (SortingFunc, optional) – Function that sorts key and reference views. Defaults to sort_key_first.

  • num_retry (int, optional) – Number of retries if no match is found. Defaults to 3.

  • match_key (str, optional) – Key to match reference views with key view. Defaults to K.boxes2d_track_ids.

  • skip_nomatch_samples (bool, optional) – Whether to skip samples where no match is found. Defaults to False.

__getitem__(index)[source]

Get item from dataset.

Return type:

list[Dict[str, Any]]

__len__()[source]

Get length of dataset.

Return type:

int

get_ref_data(ref_indices)[source]

Get reference data from dataset.

Return type:

list[Dict[str, Any]]

has_matches(key_data, ref_data)[source]

Check if key / ref data have matches.

Return type:

bool

class ReferenceViewSampler(num_ref_samples)[source]

Base reference view sampler.

Creates an instance of the class.

Parameters:

num_ref_samples (int) – Number of reference views to sample.

abstract __call__(key_dataset_index, indices_in_video, frame_ids)[source]

Sample num_ref_samples reference view indices.

Parameters:
  • key_index (int) – Index of key view in the video.

  • indices_in_video (list[int]) – All dataset indices in the video.

  • frame_ids (list[int]) – Frame ids of all views in the video.

Returns:

dataset indices of reference views.

Return type:

list[int]

class SequentialViewSampler(num_ref_samples)[source]

Sequential View Sampler.

Creates an instance of the class.

Parameters:

num_ref_samples (int) – Number of reference views to sample.

__call__(key_dataset_index, indices_in_video, frame_ids)[source]

Sample sequential reference views.

Return type:

list[int]

class UniformViewSampler(scope, num_ref_samples)[source]

View Sampler that chooses reference views uniform at random.

Creates an instance of the class.

Parameters:
  • scope (int) – Define scope of neighborhood to key view to sample from.

  • num_ref_samples (int) – Number of reference views to sample.

__call__(key_dataset_index, indices_in_video, frame_ids)[source]

Uniformly sample reference views.

Return type:

list[int]

sort_key_first(cur_sample, ref_data)[source]

Sort views as key first.

Return type:

list[Dict[str, Any]]

sort_temporal(cur_sample, ref_data)[source]

Sort views temporally.

Return type:

list[Dict[str, Any]]