fruit_project.utils.datasets.det_dataset¶
Classes¶
A custom dataset class for object detection tasks. |
Module Contents¶
- class fruit_project.utils.datasets.det_dataset.DET_DS(root_dir: str, type: str, image_dir: str, label_dir: str, config_file: str, transforms: albumentations.Compose = None, input_size: int = 224)[source]¶
Bases:
torch.utils.data.Dataset
A 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.
- Type:
str
- transforms[source]¶
A function or object to apply transformations to the images and annotations.
- Type:
Albumentations Compose, optional
- Parameters:
root_dir (str) – The root directory containing the dataset.
type (str) – The type of dataset (e.g., ‘train’, ‘val’, ‘test’).
image_dir (str) – The subdirectory containing the images.
label_dir (str) – The subdirectory containing the label files.
config_file (str) – The path to the configuration file containing class names.
transforms (Albumentations Compose, optional) – A function or object to apply transformations to the images and annotations.
input_size (int, optional) – The input size for the images (default is 224).
- 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