lab4d.dataloader package¶
lab4d.dataloader.data_utils¶
- class lab4d.dataloader.data_utils.FrameInfo(ref_list)¶
Bases:
object
Metadata about the frames in a dataset
- lab4d.dataloader.data_utils.config_to_dataset(opts, is_eval=False, gpuid=[])¶
Construct a PyTorch dataset that includes all videos in a sequence.
- lab4d.dataloader.data_utils.duplicate_dataset(opts, datalist)¶
Duplicate a list of per-video datasets, so that the length matches the desired number of iterations per round during training.
- Parameters:
datalist (List(VidDataset)) – A list of per-video datasets
- Returns:
datalist_mul (List(VidDataset)) – Duplicated dataset list
- lab4d.dataloader.data_utils.eval_loader(opts_dict)¶
Construct the evaluation dataloader.
- Parameters:
opts_dict (Dict) – Defined in Trainer::construct_dataset_opts()
- Returns:
dataloader (torch.utils.data.DataLoader) – Evaluation dataloader
- lab4d.dataloader.data_utils.get_data_info(loader)¶
Extract dataset metadata from a dataloader
- Parameters:
loader (torch.utils.data.DataLoader) – Evaluation dataloader
- Returns:
data_info (Dict) – Dataset metadata
- lab4d.dataloader.data_utils.get_vid_length(inst_id, data_info)¶
Compute the length of a video
- Parameters:
inst_id (int) – Video to check
data_info (Dict) – Dataset metadata
- lab4d.dataloader.data_utils.load_config(config, dataname, current_dict=None)¶
Load a section from a .config metadata file
- Parameters:
config (RawConfigParser) – Config parser object
dataname (str) – Name of section to load
currect_dict (Dict) – If given, load into an existing dict. Otherwise return a new dict
- lab4d.dataloader.data_utils.load_small_files(data_path_dict)¶
For a sequence of videos, load small dataset files into memory
- lab4d.dataloader.data_utils.merge_dict_list(loader)¶
For a sequence of videos, construct a dict .npy/.txt paths that contain all the frame data and annotations from the whole sequence
- Parameters:
loader (torch.utils.data.DataLoader) – Dataloader for a video sequence
- Returns:
dict_list (Dict(str, List(str))) – Maps each frame/annotation type to a list of .npy/.txt paths for that type
- lab4d.dataloader.data_utils.section_to_dataset(opts, config, vidid)¶
Construct a PyTorch dataset for a single video in a sequence using opts[“dataset_constructor”]
- Parameters:
opts (Dict) – Defined in Trainer::construct_dataset_opts()
config (RawConfigParser) – Config parser object
vidid (int) – Which video in the sequence
- Returns:
dataset (torch.utils.data.Dataset) – Dataset for the video
- lab4d.dataloader.data_utils.train_loader(opts_dict)¶
Construct the training dataloader.
- Parameters:
opts_dict (Dict) – Defined in Trainer::construct_dataset_opts()
- Returns:
dataloader (
torch.utils.data.DataLoader
) – Training dataloader
lab4d.dataloader.vidloader¶
- class lab4d.dataloader.vidloader.RangeSampler(num_elems)¶
Bases:
object
Sample efficiently without replacement from the range [0, num_elems).
- Parameters:
num_elems (int) – Upper bound of sample range
- init_queue()¶
Compute the next set of samples by permuting the sample range
- class lab4d.dataloader.vidloader.VidDataset(opts, rgblist, dataid, ks, raw_size)¶
Bases:
Dataset
Frame data and annotations for a single video in a sequence. Uses np.mmap internally to load larger-than-memory frame data from disk.
- Parameters:
- construct_data_list(reflist, prefix, feature_type)¶
Construct a dict of .npy/.txt paths that contain all the frame data and annotations for a particular video
- Parameters:
- Returns:
dict_list (Dict(str, List(str))) – Maps each frame/annotation type to a list of .npy/.txt paths for that type
- load_data(im0idx)¶
Sample pixels from a pair of frames
- Parameters:
im0idx (int) – First frame id in the pair
- Returns:
data_dict (Dict) – Maps keys to (2, …) data
- load_data_list(dict_list)¶
Load all the frame data and anotations in this dataset
- read_depth(im0idx, rand_xy=None)¶
Read depth map for a single frame
- Parameters:
im0idx (int) – Frame id to load
rand_xy (np.array or None) – (N,2) Pixels to load, if given
- Returns:
depth (np.array) – (H,W,1) or (N,1) Depth map, float16
- read_feature(im0idx, rand_xy=None)¶
Read feature map for a single frame
- Parameters:
im0idx (int) – Frame id to load
rand_xy (np.array or None) – (N,2) Pixels to load, if given
- Returns:
feat (np.array) – (112,112,16) or (N,16) Feature map, float32
- read_flow(im0idx, delta, rand_xy=None)¶
Read flow map for a single frame
- read_mask(im0idx, rand_xy=None)¶
Read segmentation and object-centric bounding box for a single frame
- Parameters:
im0idx (int) – Frame id to load
rand_xy (np.array or None) – (N,2) Pixels to load, if given
- Returns:
mask (np.array) – (H,W,1) or (N,1) Segmentation mask, bool
vis2d (np.array) – (H,W,1) or (N,1) Mask of whether each pixel is part of the original frame, bool. For full frames, the entire mask is True
crop2raw (np.array) – (4,) Camera-intrinsics-style transformation from cropped (H,W) image to raw image, (fx, fy, cx, cy)
- read_raw(im0idx, delta, rand_xy=None)¶
Read video data for a single frame within a pair
- read_rgb(im0idx, rand_xy=None)¶
Read RGB data for a single frame
- Parameters:
im0idx (int) – Frame id to load
rand_xy (np.array or None) – (N, 2) Pixels to load, if given
- Returns:
rgb (np.array) – (H,W,3) or (N, 3) Pixels, 0 to 1, float16
- sample_delta(index)¶
Sample random delta frame
- Parameters:
index (int) – First index in the pair
- Returns:
delta (int) – Delta between first and second index
- sample_xy()¶
Sample random pixels from an image
- Returns:
xy – (N, 2) Sampled pixels