vis4d.data.io¶
Init io module.
- class DataBackend[source]¶
Abstract class of storage backends.
All backends need to implement three functions: get(), set() and exists(). get() reads the file as a byte stream and set() writes a byte stream to a file. exists() checks if a certain filepath exists.
- abstract exists(filepath)[source]¶
Check if filepath exists.
- Parameters:
filepath (str) – The filepath to check.
- Returns:
True if the filepath exists, False otherwise.
- Return type:
bool
- abstract get(filepath)[source]¶
Get the file content at the given filepath as bytes.
- Parameters:
filepath (str) – The filepath to retrieve the data from.”
- Returns:
The content of the file as bytes.
- Return type:
bytes
- abstract isfile(filepath)[source]¶
Check if filepath is a file.
- Parameters:
filepath (str) – The filepath to check.
- Returns:
True if the filepath is a file, False otherwise.
- Return type:
bool
- class FileBackend[source]¶
Raw file from hard disk data backend.
- 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 file content as bytes.
- Parameters:
filepath (str) – Path to file.
- Raises:
FileNotFoundError – If filepath does not exist.
- Returns:
File content as bytes.
- Return type:
bytes
- isfile(filepath)[source]¶
Check if filepath is a file.
- Parameters:
filepath (str) – Path to file.
- Returns:
True if file exists, False otherwise.
- Return type:
bool
- 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.
- 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/key3content (
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
- class ZipBackend[source]¶
Backend for loading data from Zip files.
This backend works with filepaths pointing to valid Zip files. We assume that the given Zip file contains the whole dataset associated to this backend.
Creates an instance of the class.
- 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 Zip path together with the relative path inside it, e.g.: “/path/to/ file.zip/key/subkey/data”. If no .zip given inside filepath, the function will search for the first .zip file present in the path, i.e. “/path/to/file/key/subkey/data” will also /key/ subkey/data from /path/to/file.zip.
- Raises:
ZipFileNotFoundError – If no suitable file exists.
OSError – If the file cannot be opened.
ValueError – If key not found inside zip 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.
- Returns:
True if file exists, False otherwise.
- Return type:
bool
- listdir(filepath)[source]¶
List all files in the given directory.
- Parameters:
filepath (str) – The path to the directory.
- Returns:
List of all files in the given directory.
- Return type:
list[str]
- set(filepath, content, mode='w')[source]¶
Write the file content to the zip file.
- Parameters:
filepath (
str
) – path/to/file.zip/key1/key2/key3content (
bytes
) – Bytes to be written to entry key3 within group key2 within another group key1, for example.mode (
Literal
['w'
,'a'
]) – Mode to open the file in. “w” for writing a file, “a” for appending to existing file.
- Raises:
ValueError – If filepath is not a valid .zip file
NotImplementedError – If the method is not implemented.
- Return type:
None
Modules
Backends for the data types a dataset of interest is saved in. |
|
Standard backend for local files on a hard drive. |
|
Hdf5 data backend. |
|
Data I/O Utilities. |
|
Zip data backend. |