Datasets¶
- class flat_bug.datasets.FlatBugYOLODataset(max_instances: int | None, classes: None = None, subset_args: Dict | None = None, *args, **kwargs)¶
- build_transforms(hyp: IterableSimpleNamespace) Compose ¶
Builds and appends transforms to the list.
- Parameters:
hyp (dict, optional) – Hyperparameters for transforms.
- Returns:
Composed transforms.
- Return type:
(Compose)
- cache_labels(path: Path = PosixPath('labels.cache'))¶
OBS: DO NOT USE THIS FUNCTION MANUALLY.
- load_image(i: int | slice) Tuple[ndarray, Tuple[int, int], Tuple[int, int]] ¶
Load an image from dataset index ‘i’.
- Parameters:
i (int) – Index of the image to load.
rect_mode (bool, optional) – Whether to use rectangular resizing.
- Returns:
Loaded image as a NumPy array. (Tuple[int, int]): Original image dimensions in (height, width) format. (Tuple[int, int]): Resized image dimensions in (height, width) format.
- Return type:
(np.ndarray)
- Raises:
FileNotFoundError – If the image file is not found.
- class flat_bug.datasets.FlatBugYOLOValidationDataset(max_instances: int | None, classes: None = None, subset_args: Dict | None = None, *args, **kwargs)¶
- build_transforms(hyp: IterableSimpleNamespace) Compose ¶
Builds and appends transforms to the list.
- Parameters:
hyp (dict, optional) – Hyperparameters for transforms.
- Returns:
Composed transforms.
- Return type:
(Compose)
- flat_bug.datasets.calculate_image_weights(image_paths: List[str]) List[float] ¶
Calculate normalized weights for each image based on the file sizes, normalized by the minimum file size, so that the values are between 1 and infinity.
- Parameters:
image_paths (List[str]) – List of image file paths.
- Returns:
normalized weights for each image.
- Return type:
out (List[float])
- flat_bug.datasets.generate_indices(weights: List[float], target_size: int | None = None) List[int] ¶
Deterministically generates a list of indices based on the provided weights to oversample the items.
- Parameters:
weights (List[float]) – List of weights for each item.
target_size (Optional[int], optional) – Desired size of the output list. If None, the size of the output is approximately the sum of the weights.
- Returns:
List of indices to oversample the items.
- Return type:
out (List[int])
- flat_bug.datasets.reweight(weights: List[float], target_sum: float | int) List[float] ¶
Reweights the provided list of weights so that their sum equals the target sum.
- Parameters:
weights (List[float]) – List of weights to reweight.
target_sum (Union[float, int]) – Desired sum of the weights.
- Returns:
Reweighted weights.
- Return type:
out (List[float])
- flat_bug.datasets.subset(self: FlatBugYOLODataset, n: int | None = None, pattern: str | None = None)¶
Subsets the dataset to the first ‘n’ elements that match the pattern.
- Parameters:
n (Optional[int], optional) – The number of elements to keep. Defaults to None; keep all.
pattern (Optional[str], optional) – A regex pattern to match the filenames. Defaults to None; match all.