Utilities
Utility functions shared across dataset classes.
- src.utils.check_type(value: object, expected_type: type | tuple, name: str) None[source]
Raise TypeError if value is not an instance of expected_type.
- Parameters:
value – The value to check.
expected_type – The expected type or tuple of types.
name – The parameter name (used in the error message).
- Raises:
TypeError – If value is not of the expected type.
- src.utils.check_range(value: float, min_val: float, max_val: float, name: str) None[source]
Raise ValueError if value is not within [min_val, max_val].
- Parameters:
value – The numeric value to check.
min_val – The minimum allowed value (inclusive).
max_val – The maximum allowed value (inclusive).
name – The parameter name (used in the error message).
- Raises:
ValueError – If value is outside the allowed range.
- src.utils.parse_labels_csv(labels_file: str) dict[str, str][source]
Parse a CSV file mapping filenames to labels.
- The CSV is expected to have no header row. Each row contains:
column 0: filename (basename only, e.g.
image.jpg)column 1: label (string; callers may cast to int/float as needed)
- Parameters:
labels_file – Absolute or relative path to the CSV file.
- Returns:
A dict mapping each filename to its label string.
- Raises:
FileNotFoundError – If labels_file does not exist.
ValueError – If the CSV contains a row with fewer than two columns.
- src.utils.load_image(path: str) ndarray[source]
Load an image from disk as an RGB numpy array.
- Parameters:
path – Path to the image file (.jpg, .jpeg, or .png).
- Returns:
A numpy array of shape (H, W, 3) with dtype uint8.
- Raises:
FileNotFoundError – If the file does not exist.
OSError – If Pillow cannot open the file.