vis4d.data.io.hdf5

Hdf5 data backend.

This backend works with filepaths pointing to valid HDF5 files. We assume that the given HDF5 file contains the whole dataset associated to this backend.

Functions

convert_dataset(source_dir)

Convert a dataset to HDF5 format.

Classes

HDF5Backend()

Backend for loading data from HDF5 files.

class HDF5Backend[source]

Backend for loading data from HDF5 files.

This backend works with filepaths pointing to valid HDF5 files. We assume that the given HDF5 file contains the whole dataset associated to this backend.

You can use the provided script at vis4d/data/datasets/to_hdf5.py to convert your dataset to the expected hdf5 format before using this backend.

Creates an instance of the class.

close()[source]

Close all opened HDF5 files.

Return type:

None

exists(filepath)[source]

Check if filepath exists.

Parameters:

filepath (str) – Path to file.

Returns:

True if file exists, False otherwise.

Return type:

bool

get(filepath)[source]

Get values according to the filepath as bytes.

Parameters:

filepath (str) – The path to the file. It consists of an HDF5 path together with the relative path inside it, e.g.: “/path/to/ file.hdf5/key/subkey/data”. If no .hdf5 given inside filepath, the function will search for the first .hdf5 file present in the path, i.e. “/path/to/file/key/subkey/data” will also /key/ subkey/data from /path/to/file.hdf5.

Raises:
  • FileNotFoundError – If no suitable file exists.

  • ValueError – If key not found inside hdf5 file.

Returns:

The file content in bytes

Return type:

bytes

isfile(filepath)[source]

Check if filepath is a file.

Parameters:

filepath (str) – Path to file.

Raises:
  • FileNotFoundError – If no suitable file exists.

  • ValueError – If key not found inside hdf5 file.

Returns:

True if file exists, False otherwise.

Return type:

bool

listdir(filepath)[source]

List all files in the given directory.

Parameters:

filepath (str) – Path to directory.

Raises:
  • FileNotFoundError – If no suitable file exists.

  • ValueError – If key not found inside hdf5 file.

Returns:

List of files in the given directory.

Return type:

list[str]

set(filepath, content, mode='a')[source]

Set the file content.

Parameters:
  • filepath (str) – path/to/file.hdf5/key1/key2/key3

  • content (bytes) – Bytes to be written to entry key3 within group key2 within another group key1, for example.

  • mode (Literal['w', 'a']) – “w” to overwrite the file, “a” to append to it.

Raises:

ValueError – If filepath is not a valid .hdf5 file

Return type:

None

convert_dataset(source_dir)[source]

Convert a dataset to HDF5 format.

This function converts an arbitary dictionary to an HDF5 file. The keys inside the HDF5 file preserve the directory structure of the original.

As an example, if you convert “/path/to/dataset” to HDF5, the resulting file will be: “/path/to/dataset.hdf5”. The file “relative/path/to/file” will be stored at “relative/path/to/file” inside /path/to/dataset.hdf5.

Parameters:

source_dir (str) – The path to the dataset to convert.

Return type:

None