Data¶
Dataset¶
yolo.data.dataset
¶
logger = logging.getLogger('yolo')
module-attribute
¶
DataConfig
dataclass
¶
Source code in yolo/config/schemas/data.py
DatasetConfig
dataclass
¶
RemoveOutliers
¶
Removes outlier bounding boxes that are too small or have invalid dimensions.
Source code in yolo/data/augmentation.py
__init__(min_box_area=1e-08)
¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
min_box_area
|
float
|
Minimum area for a box to be kept, as a fraction of the image area. |
1e-08
|
__call__(image, boxes)
¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
Image
|
The cropped image. |
required |
boxes
|
Tensor
|
Bounding boxes in normalized coordinates (x_min, y_min, x_max, y_max). |
required |
Returns: PIL.Image: The input image (unchanged). torch.Tensor: Filtered bounding boxes.
Source code in yolo/data/augmentation.py
PadAndResize
¶
Source code in yolo/data/augmentation.py
__init__(image_size, background_color=(114, 114, 114))
¶
Initialize the object with the target image size.
HorizontalFlip
¶
Randomly horizontally flips the image along with the bounding boxes.
Source code in yolo/data/augmentation.py
VerticalFlip
¶
Randomly vertically flips the image along with the bounding boxes.
Source code in yolo/data/augmentation.py
Mosaic
¶
Applies the Mosaic augmentation to a batch of images and their corresponding boxes.
Source code in yolo/data/augmentation.py
MixUp
¶
Applies the MixUp augmentation to a pair of images and their corresponding boxes.
Source code in yolo/data/augmentation.py
RandomCrop
¶
Randomly crops the image to half its size along with adjusting the bounding boxes.
Source code in yolo/data/augmentation.py
AugmentationComposer
¶
Composes several transforms together.
Source code in yolo/data/augmentation.py
YoloDataset
¶
Bases: Dataset
Source code in yolo/data/dataset.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 | |
load_data(dataset_path, phase_name)
¶
Loads data from a cache or generates a new cache for a specific dataset phase.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_path
|
Path
|
The root path to the dataset directory. |
required |
phase_name
|
str
|
The specific phase of the dataset (e.g., 'train', 'test') to load or generate data for. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
list |
list
|
The loaded data from the cache for the specified phase. |
Source code in yolo/data/dataset.py
filter_data(dataset_path, phase_name, sort_image=False)
¶
Filters and collects dataset information by pairing images with their corresponding labels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_path
|
Path
|
Root path of the dataset directory. |
required |
phase_name
|
str
|
Dataset split to load (e.g. |
required |
sort_image
|
bool
|
If True, sorts the dataset by the width-to-height ratio of images in descending order. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
list |
list
|
A list of tuples, each containing the path to an image file and its associated segmentation as a tensor. |
Source code in yolo/data/dataset.py
load_valid_labels(label_path, seg_data_one_img)
¶
Loads valid COCO style segmentation data (values between [0, 1]) and converts it to bounding box coordinates by finding the minimum and maximum x and y values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label_path
|
str
|
The filepath to the label file containing annotation data. |
required |
seg_data_one_img
|
list
|
The actual list of annotations (in segmentation format) |
required |
Returns:
| Type | Description |
|---|---|
Union[Tensor, None]
|
Tensor or None: A tensor of all valid bounding boxes if any are found; otherwise, None. |
Source code in yolo/data/dataset.py
prepare_dataset(dataset_cfg, task)
¶
Prepares dataset by downloading and unzipping if necessary.
Source code in yolo/data/preparation.py
create_image_metadata(labels_path)
¶
Create a dictionary containing image information and annotations indexed by image ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
labels_path
|
str
|
The path to the annotation json file. |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, List]
|
|
Dict[str, Dict]
|
|
Source code in yolo/utils/dataset_utils.py
locate_label_paths(dataset_path, phase_name)
¶
Find the path to label files for a specified dataset and phase(e.g. training).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_path
|
Path
|
The path to the root directory of the dataset. |
required |
phase_name
|
Path
|
The name of the phase for which labels are being searched (e.g., "train", "val", "test"). |
required |
Returns:
| Type | Description |
|---|---|
Tuple[Path, Path]
|
Tuple[Path, Path]: A tuple containing the path to the labels file and the file format ("json" or "txt"). |
Source code in yolo/utils/dataset_utils.py
scale_segmentation(annotations, image_dimensions)
¶
Scale the segmentation data based on image dimensions and return a list of scaled segmentation data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
annotations
|
List[Dict[str, Any]]
|
A list of annotation dictionaries. |
required |
image_dimensions
|
Dict[str, int]
|
A dictionary containing image dimensions (height and width). |
required |
Returns:
| Type | Description |
|---|---|
Optional[List[List[float]]]
|
Optional[List[List[float]]]: A list of scaled segmentation data, where each sublist contains category_id followed by scaled (x, y) coordinates. |
Source code in yolo/utils/dataset_utils.py
tensorlize(data)
¶
Source code in yolo/utils/dataset_utils.py
collate_fn(batch)
¶
A collate function to handle batching of images and their corresponding targets.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
list of tuples
|
Each tuple contains: - image (Tensor): The image tensor. - labels (Tensor): The tensor of labels for the image. |
required |
Returns:
| Type | Description |
|---|---|
Tuple[Tensor, List[Tensor]]
|
Tuple[Tensor, List[Tensor]]: A tuple containing: - A tensor of batched images. - A list of tensors, each corresponding to bboxes for each image in the batch. |
Source code in yolo/data/dataset.py
Loader¶
yolo.data.loader
¶
DataConfig
dataclass
¶
Source code in yolo/config/schemas/data.py
DatasetConfig
dataclass
¶
AugmentationComposer
¶
Composes several transforms together.
Source code in yolo/data/augmentation.py
YoloDataset
¶
Bases: Dataset
Source code in yolo/data/dataset.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 | |
load_data(dataset_path, phase_name)
¶
Loads data from a cache or generates a new cache for a specific dataset phase.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_path
|
Path
|
The root path to the dataset directory. |
required |
phase_name
|
str
|
The specific phase of the dataset (e.g., 'train', 'test') to load or generate data for. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
list |
list
|
The loaded data from the cache for the specified phase. |
Source code in yolo/data/dataset.py
filter_data(dataset_path, phase_name, sort_image=False)
¶
Filters and collects dataset information by pairing images with their corresponding labels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_path
|
Path
|
Root path of the dataset directory. |
required |
phase_name
|
str
|
Dataset split to load (e.g. |
required |
sort_image
|
bool
|
If True, sorts the dataset by the width-to-height ratio of images in descending order. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
list |
list
|
A list of tuples, each containing the path to an image file and its associated segmentation as a tensor. |
Source code in yolo/data/dataset.py
load_valid_labels(label_path, seg_data_one_img)
¶
Loads valid COCO style segmentation data (values between [0, 1]) and converts it to bounding box coordinates by finding the minimum and maximum x and y values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label_path
|
str
|
The filepath to the label file containing annotation data. |
required |
seg_data_one_img
|
list
|
The actual list of annotations (in segmentation format) |
required |
Returns:
| Type | Description |
|---|---|
Union[Tensor, None]
|
Tensor or None: A tensor of all valid bounding boxes if any are found; otherwise, None. |
Source code in yolo/data/dataset.py
StreamDataLoader
¶
Source code in yolo/data/loader.py
collate_fn(batch)
¶
A collate function to handle batching of images and their corresponding targets.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
list of tuples
|
Each tuple contains: - image (Tensor): The image tensor. - labels (Tensor): The tensor of labels for the image. |
required |
Returns:
| Type | Description |
|---|---|
Tuple[Tensor, List[Tensor]]
|
Tuple[Tensor, List[Tensor]]: A tuple containing: - A tensor of batched images. - A list of tensors, each corresponding to bboxes for each image in the batch. |
Source code in yolo/data/dataset.py
prepare_dataset(dataset_cfg, task)
¶
Prepares dataset by downloading and unzipping if necessary.
Source code in yolo/data/preparation.py
create_dataloader(data_cfg, dataset_cfg, task='train')
¶
Source code in yolo/data/loader.py
Augmentation¶
yolo.data.augmentation
¶
AugmentationComposer
¶
Composes several transforms together.
Source code in yolo/data/augmentation.py
RemoveOutliers
¶
Removes outlier bounding boxes that are too small or have invalid dimensions.
Source code in yolo/data/augmentation.py
__init__(min_box_area=1e-08)
¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
min_box_area
|
float
|
Minimum area for a box to be kept, as a fraction of the image area. |
1e-08
|
__call__(image, boxes)
¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
Image
|
The cropped image. |
required |
boxes
|
Tensor
|
Bounding boxes in normalized coordinates (x_min, y_min, x_max, y_max). |
required |
Returns: PIL.Image: The input image (unchanged). torch.Tensor: Filtered bounding boxes.
Source code in yolo/data/augmentation.py
PadAndResize
¶
Source code in yolo/data/augmentation.py
__init__(image_size, background_color=(114, 114, 114))
¶
Initialize the object with the target image size.
HorizontalFlip
¶
Randomly horizontally flips the image along with the bounding boxes.
Source code in yolo/data/augmentation.py
VerticalFlip
¶
Randomly vertically flips the image along with the bounding boxes.
Source code in yolo/data/augmentation.py
Mosaic
¶
Applies the Mosaic augmentation to a batch of images and their corresponding boxes.
Source code in yolo/data/augmentation.py
MixUp
¶
Applies the MixUp augmentation to a pair of images and their corresponding boxes.
Source code in yolo/data/augmentation.py
RandomCrop
¶
Randomly crops the image to half its size along with adjusting the bounding boxes.
Source code in yolo/data/augmentation.py
Preparation¶
yolo.data.preparation
¶
logger = logging.getLogger('yolo')
module-attribute
¶
DatasetConfig
dataclass
¶
download_file(url, destination)
¶
Downloads a file from the specified URL to the destination path with progress logging.
Source code in yolo/data/preparation.py
unzip_file(source, destination)
¶
Extracts a ZIP file to the specified directory and removes the ZIP file after extraction.
Source code in yolo/data/preparation.py
check_files(directory, expected_count=None)
¶
Returns True if the number of files in the directory matches expected_count, False otherwise.
Source code in yolo/data/preparation.py
prepare_dataset(dataset_cfg, task)
¶
Prepares dataset by downloading and unzipping if necessary.