visionsim.dataset package

Submodules

visionsim.dataset.dataset module

visionsim.dataset.dataset.default_collate(batch: Iterable[tuple[int, npt.NDArray, npt.NDArray]]) tuple[npt.NDArray, npt.NDArray, npt.NDArray][source]

Collate function that takes in a batch of [(img_idx, img, pose), …] and returns (img_idxs, imgs, poses)

Parameters:

batch (Iterable[tuple[int, npt.NDArray, npt.NDArray]]) – Iterable of tuples (img_idx, img, pose).

Returns

Collated numpy arrays of img_idxs, imgs, poses.

class visionsim.dataset.dataset.Dataset[source]

Bases: Dataset

Base dataset implementation

__init__() None[source]
classmethod from_path(root: str | PathLike, mode: Literal['img', 'npy'] | None = None) NpyDataset | ImgDataset[source]

Given a dataset root, resolve it and instantiate the correct dataset type.

Parameters:
  • root (str | os.PathLike) – path to dataset, either containing folder or transforms.json.

  • mode (Literal['img', 'npy'] | None, optional) – if type of dataset is known, it can be provided, otherwise it will try to be inferred. Expects either ‘img’ or ‘npy’. Defaults to None (infer).

Raises:
  • ValueError – raise if mode is not understood.

  • RuntimeError – raised if dataset type can not be determined.

Returns:

dataset instance, either a NpyDataset or ImgDataset.

property arclength: float[source]

Calculate the length of the trajectory

class visionsim.dataset.dataset.ImgDataset(root: str | PathLike)[source]

Bases: Dataset

Dataset to iterate over frames (stored as image files) and optionally poses (as .json).

__init__(root: str | PathLike) None[source]

Initialize an ImgDataset, same as Dataset.from_path(root, mode=”img”).

Parameters:

root (str | os.PathLike) – path to dataset, either containing folder or transforms.json.

property full_shape: tuple[int, int, int, int][source]

Get shape of dataset as (N, H, W, C).

class visionsim.dataset.dataset.ImgDatasetWriter(root: str | PathLike, transforms: dict | None = None, pattern: str = 'frame_{:06}.png', force=False)[source]

Bases: object

ImgDataset writer implemented as a context manager.

Example

with NpyDatasetWriter(root, transforms=...) as writer:
    for idxs, data, poses in dataset:
        # Apply any transforms here
        writer[idxs] = (data, poses)
__init__(root: str | PathLike, transforms: dict | None = None, pattern: str = 'frame_{:06}.png', force=False) None[source]

Initialize ImgDatasetWriter.

Parameters:
  • root (str | os.PathLike) – directory in which to save dataset (both frames/*.png and optionally .json)

  • transforms (dict | None, optional) – transforms of source dataset, frames are discarded and camera info is kept. Defaults to None.

  • pattern (str, optional) – frame filename pattern, will be formatted with frame index. Defaults to “frame_{:06}.png”.

  • force (bool, optional) – if true, overwrite output file(s) if present. Defaults to False.

Raises:

FileExistsError – raised if dataset exists at requested location and force is false.

class visionsim.dataset.dataset.NpyDataset(root: str | PathLike)[source]

Bases: Dataset

Dataset to iterate over frames (stored as a possibly bitpacked npy file) and optionally poses (as .json).

__init__(root: str | PathLike) None[source]

Initialize an NpyDataset, same as Dataset.from_path(root, mode=”npy”).

Parameters:

root (str | os.PathLike) – path to dataset, either containing folder or transforms.json.

class visionsim.dataset.dataset.NpyDatasetWriter(root: str | PathLike, shape: tuple[int, ...], transforms=None, force=False, strict=True)[source]

Bases: object

NpyDataset writer implemented as a context manager.

Example

src_dataset = ImgDataset(input_dir)
loader = DataLoader(src_dataset, ...)

with NpyDatasetWriter(root, shape, transforms=...) as writer:
    for idxs, data, poses in loader:
        # Apply any transforms here
        writer[idxs] = (data, poses)
__init__(root: str | PathLike, shape: tuple[int, ...], transforms=None, force=False, strict=True) None[source]

Initialize NpyDatasetWriter.

Parameters:
  • root (str | os.PathLike) – directory in which to save dataset (both .npy and optionally .json)

  • shape (tuple[int, ...]) – shape of resulting array, must be known ahead of time for npy file creation

  • transforms (dict | None, optional) – transforms of source dataset, frames are discarded and camera info is kept. Defaults to None.

  • force (bool, optional) – if true, overwrite output file(s) if present. Defaults to False.

  • strict (bool, optional) – if true, throw error if the whole dataset has not been filled. Defaults to True.

Raises:

FileExistsError – raised if dataset exists at requested location and force is false.

visionsim.dataset.schema module

visionsim.dataset.schema.read_and_validate(*, path, schema)[source]

Load a json from a file and check that it complies with the provided schema.

visionsim.dataset.schema.validate_and_write(*, path, schema, transforms)[source]

Dump json to a file and check that it complies with the provided schema.

Module contents