fruit_project.utils.datasets.det_dataset¶
Classes¶
A custom dataset class for object detection tasks. |
Functions¶
|
Convert back to HF format |
Module Contents¶
- class fruit_project.utils.datasets.det_dataset.DET_DS(root_dir: str | None, split: str, config_file: str, transforms: albumentations.Compose | None = None, processor=None, normalize: bool = False)[source]¶
Bases:
torch.utils.data.DatasetA custom dataset class for object detection tasks.
This dataset class loads images and their corresponding labels from specified directories, applies transformations if provided, and returns the processed image along with target annotations.
- config_file¶
The path to the configuration file containing class names and folder structure.
- Type:
str
- transforms[source]¶
A function or object to apply transformations to the images and annotations.
- Type:
Albumentations Compose, optional
- The configuration file (YAML) should contain:
names: List of class names
folders (optional): Dictionary with keys ‘images’, ‘labels’, ‘train’, ‘val’, ‘test’ specifying the folder names. Defaults to standard names if not provided.
folders.structure (optional): Either ‘type_first’ (default) for images/train structure or ‘split_first’ for train/images structure.
- Parameters:
root_dir (str) – The root directory containing the dataset.
split (str) – The dataset split (e.g., ‘train’, ‘val’, ‘test’).
config_file (str) – The path to the configuration file containing class names and folder structure.
transforms (Albumentations Compose, optional) – A function or object to apply transformations to the images and annotations.
- Raises:
FileNotFoundError – If the configuration file or label files are not found.
ValueError – If an image cannot be loaded or is invalid.
- __getitem__(idx)[source]¶
Retrieves the processed image and target annotations for the given index.
- Parameters:
idx (int) – The index of the image to retrieve.
- Returns:
- A tuple containing:
img (numpy.ndarray): The processed image.
- target (dict): A dictionary containing target annotations, including:
image_id (int): The index of the image.
annotations (list): A list of dictionaries with bounding box, category ID, area, and iscrowd flag.
orig_size (torch.Tensor): The original size of the image (height, width).
- Return type:
tuple