dgenerate-ultralytics-headless 8.3.137__py3-none-any.whl → 8.3.224__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {dgenerate_ultralytics_headless-8.3.137.dist-info → dgenerate_ultralytics_headless-8.3.224.dist-info}/METADATA +41 -34
- dgenerate_ultralytics_headless-8.3.224.dist-info/RECORD +285 -0
- {dgenerate_ultralytics_headless-8.3.137.dist-info → dgenerate_ultralytics_headless-8.3.224.dist-info}/WHEEL +1 -1
- tests/__init__.py +7 -6
- tests/conftest.py +15 -39
- tests/test_cli.py +17 -17
- tests/test_cuda.py +17 -8
- tests/test_engine.py +36 -10
- tests/test_exports.py +98 -37
- tests/test_integrations.py +12 -15
- tests/test_python.py +126 -82
- tests/test_solutions.py +319 -135
- ultralytics/__init__.py +27 -9
- ultralytics/cfg/__init__.py +83 -87
- ultralytics/cfg/datasets/Argoverse.yaml +4 -4
- ultralytics/cfg/datasets/DOTAv1.5.yaml +2 -2
- ultralytics/cfg/datasets/DOTAv1.yaml +2 -2
- ultralytics/cfg/datasets/GlobalWheat2020.yaml +2 -2
- ultralytics/cfg/datasets/HomeObjects-3K.yaml +4 -5
- ultralytics/cfg/datasets/ImageNet.yaml +3 -3
- ultralytics/cfg/datasets/Objects365.yaml +24 -20
- ultralytics/cfg/datasets/SKU-110K.yaml +9 -9
- ultralytics/cfg/datasets/VOC.yaml +10 -13
- ultralytics/cfg/datasets/VisDrone.yaml +43 -33
- ultralytics/cfg/datasets/african-wildlife.yaml +5 -5
- ultralytics/cfg/datasets/brain-tumor.yaml +4 -5
- ultralytics/cfg/datasets/carparts-seg.yaml +5 -5
- ultralytics/cfg/datasets/coco-pose.yaml +26 -4
- ultralytics/cfg/datasets/coco.yaml +4 -4
- ultralytics/cfg/datasets/coco128-seg.yaml +2 -2
- ultralytics/cfg/datasets/coco128.yaml +2 -2
- ultralytics/cfg/datasets/coco8-grayscale.yaml +103 -0
- ultralytics/cfg/datasets/coco8-multispectral.yaml +2 -2
- ultralytics/cfg/datasets/coco8-pose.yaml +23 -2
- ultralytics/cfg/datasets/coco8-seg.yaml +2 -2
- ultralytics/cfg/datasets/coco8.yaml +2 -2
- ultralytics/cfg/datasets/construction-ppe.yaml +32 -0
- ultralytics/cfg/datasets/crack-seg.yaml +5 -5
- ultralytics/cfg/datasets/dog-pose.yaml +32 -4
- ultralytics/cfg/datasets/dota8-multispectral.yaml +2 -2
- ultralytics/cfg/datasets/dota8.yaml +2 -2
- ultralytics/cfg/datasets/hand-keypoints.yaml +29 -4
- ultralytics/cfg/datasets/lvis.yaml +9 -9
- ultralytics/cfg/datasets/medical-pills.yaml +4 -5
- ultralytics/cfg/datasets/open-images-v7.yaml +7 -10
- ultralytics/cfg/datasets/package-seg.yaml +5 -5
- ultralytics/cfg/datasets/signature.yaml +4 -4
- ultralytics/cfg/datasets/tiger-pose.yaml +20 -4
- ultralytics/cfg/datasets/xView.yaml +5 -5
- ultralytics/cfg/default.yaml +96 -93
- ultralytics/cfg/trackers/botsort.yaml +16 -17
- ultralytics/cfg/trackers/bytetrack.yaml +9 -11
- ultralytics/data/__init__.py +4 -4
- ultralytics/data/annotator.py +12 -12
- ultralytics/data/augment.py +531 -564
- ultralytics/data/base.py +76 -81
- ultralytics/data/build.py +206 -42
- ultralytics/data/converter.py +179 -78
- ultralytics/data/dataset.py +121 -121
- ultralytics/data/loaders.py +114 -91
- ultralytics/data/split.py +28 -15
- ultralytics/data/split_dota.py +67 -48
- ultralytics/data/utils.py +110 -89
- ultralytics/engine/exporter.py +422 -460
- ultralytics/engine/model.py +224 -252
- ultralytics/engine/predictor.py +94 -89
- ultralytics/engine/results.py +345 -595
- ultralytics/engine/trainer.py +231 -134
- ultralytics/engine/tuner.py +279 -73
- ultralytics/engine/validator.py +53 -46
- ultralytics/hub/__init__.py +26 -28
- ultralytics/hub/auth.py +30 -16
- ultralytics/hub/google/__init__.py +34 -36
- ultralytics/hub/session.py +53 -77
- ultralytics/hub/utils.py +23 -109
- ultralytics/models/__init__.py +1 -1
- ultralytics/models/fastsam/__init__.py +1 -1
- ultralytics/models/fastsam/model.py +36 -18
- ultralytics/models/fastsam/predict.py +33 -44
- ultralytics/models/fastsam/utils.py +4 -5
- ultralytics/models/fastsam/val.py +12 -14
- ultralytics/models/nas/__init__.py +1 -1
- ultralytics/models/nas/model.py +16 -20
- ultralytics/models/nas/predict.py +12 -14
- ultralytics/models/nas/val.py +4 -5
- ultralytics/models/rtdetr/__init__.py +1 -1
- ultralytics/models/rtdetr/model.py +9 -9
- ultralytics/models/rtdetr/predict.py +22 -17
- ultralytics/models/rtdetr/train.py +20 -16
- ultralytics/models/rtdetr/val.py +79 -59
- ultralytics/models/sam/__init__.py +8 -2
- ultralytics/models/sam/amg.py +53 -38
- ultralytics/models/sam/build.py +29 -31
- ultralytics/models/sam/model.py +33 -38
- ultralytics/models/sam/modules/blocks.py +159 -182
- ultralytics/models/sam/modules/decoders.py +38 -47
- ultralytics/models/sam/modules/encoders.py +114 -133
- ultralytics/models/sam/modules/memory_attention.py +38 -31
- ultralytics/models/sam/modules/sam.py +114 -93
- ultralytics/models/sam/modules/tiny_encoder.py +268 -291
- ultralytics/models/sam/modules/transformer.py +59 -66
- ultralytics/models/sam/modules/utils.py +55 -72
- ultralytics/models/sam/predict.py +745 -341
- ultralytics/models/utils/loss.py +118 -107
- ultralytics/models/utils/ops.py +118 -71
- ultralytics/models/yolo/__init__.py +1 -1
- ultralytics/models/yolo/classify/predict.py +28 -26
- ultralytics/models/yolo/classify/train.py +50 -81
- ultralytics/models/yolo/classify/val.py +68 -61
- ultralytics/models/yolo/detect/predict.py +12 -15
- ultralytics/models/yolo/detect/train.py +56 -46
- ultralytics/models/yolo/detect/val.py +279 -223
- ultralytics/models/yolo/model.py +167 -86
- ultralytics/models/yolo/obb/predict.py +7 -11
- ultralytics/models/yolo/obb/train.py +23 -25
- ultralytics/models/yolo/obb/val.py +107 -99
- ultralytics/models/yolo/pose/__init__.py +1 -1
- ultralytics/models/yolo/pose/predict.py +12 -14
- ultralytics/models/yolo/pose/train.py +31 -69
- ultralytics/models/yolo/pose/val.py +119 -254
- ultralytics/models/yolo/segment/predict.py +21 -25
- ultralytics/models/yolo/segment/train.py +12 -66
- ultralytics/models/yolo/segment/val.py +126 -305
- ultralytics/models/yolo/world/train.py +53 -45
- ultralytics/models/yolo/world/train_world.py +51 -32
- ultralytics/models/yolo/yoloe/__init__.py +7 -7
- ultralytics/models/yolo/yoloe/predict.py +30 -37
- ultralytics/models/yolo/yoloe/train.py +89 -71
- ultralytics/models/yolo/yoloe/train_seg.py +15 -17
- ultralytics/models/yolo/yoloe/val.py +56 -41
- ultralytics/nn/__init__.py +9 -11
- ultralytics/nn/autobackend.py +179 -107
- ultralytics/nn/modules/__init__.py +67 -67
- ultralytics/nn/modules/activation.py +8 -7
- ultralytics/nn/modules/block.py +302 -323
- ultralytics/nn/modules/conv.py +61 -104
- ultralytics/nn/modules/head.py +488 -186
- ultralytics/nn/modules/transformer.py +183 -123
- ultralytics/nn/modules/utils.py +15 -20
- ultralytics/nn/tasks.py +327 -203
- ultralytics/nn/text_model.py +81 -65
- ultralytics/py.typed +1 -0
- ultralytics/solutions/__init__.py +12 -12
- ultralytics/solutions/ai_gym.py +19 -27
- ultralytics/solutions/analytics.py +36 -26
- ultralytics/solutions/config.py +29 -28
- ultralytics/solutions/distance_calculation.py +23 -24
- ultralytics/solutions/heatmap.py +17 -19
- ultralytics/solutions/instance_segmentation.py +21 -19
- ultralytics/solutions/object_blurrer.py +16 -17
- ultralytics/solutions/object_counter.py +48 -53
- ultralytics/solutions/object_cropper.py +22 -16
- ultralytics/solutions/parking_management.py +61 -58
- ultralytics/solutions/queue_management.py +19 -19
- ultralytics/solutions/region_counter.py +63 -50
- ultralytics/solutions/security_alarm.py +22 -25
- ultralytics/solutions/similarity_search.py +107 -60
- ultralytics/solutions/solutions.py +343 -262
- ultralytics/solutions/speed_estimation.py +35 -31
- ultralytics/solutions/streamlit_inference.py +104 -40
- ultralytics/solutions/templates/similarity-search.html +31 -24
- ultralytics/solutions/trackzone.py +24 -24
- ultralytics/solutions/vision_eye.py +11 -12
- ultralytics/trackers/__init__.py +1 -1
- ultralytics/trackers/basetrack.py +18 -27
- ultralytics/trackers/bot_sort.py +48 -39
- ultralytics/trackers/byte_tracker.py +94 -94
- ultralytics/trackers/track.py +7 -16
- ultralytics/trackers/utils/gmc.py +37 -69
- ultralytics/trackers/utils/kalman_filter.py +68 -76
- ultralytics/trackers/utils/matching.py +13 -17
- ultralytics/utils/__init__.py +251 -275
- ultralytics/utils/autobatch.py +19 -7
- ultralytics/utils/autodevice.py +68 -38
- ultralytics/utils/benchmarks.py +169 -130
- ultralytics/utils/callbacks/base.py +12 -13
- ultralytics/utils/callbacks/clearml.py +14 -15
- ultralytics/utils/callbacks/comet.py +139 -66
- ultralytics/utils/callbacks/dvc.py +19 -27
- ultralytics/utils/callbacks/hub.py +8 -6
- ultralytics/utils/callbacks/mlflow.py +6 -10
- ultralytics/utils/callbacks/neptune.py +11 -19
- ultralytics/utils/callbacks/platform.py +73 -0
- ultralytics/utils/callbacks/raytune.py +3 -4
- ultralytics/utils/callbacks/tensorboard.py +9 -12
- ultralytics/utils/callbacks/wb.py +33 -30
- ultralytics/utils/checks.py +163 -114
- ultralytics/utils/cpu.py +89 -0
- ultralytics/utils/dist.py +24 -20
- ultralytics/utils/downloads.py +176 -146
- ultralytics/utils/errors.py +11 -13
- ultralytics/utils/events.py +113 -0
- ultralytics/utils/export/__init__.py +7 -0
- ultralytics/utils/{export.py → export/engine.py} +81 -63
- ultralytics/utils/export/imx.py +294 -0
- ultralytics/utils/export/tensorflow.py +217 -0
- ultralytics/utils/files.py +33 -36
- ultralytics/utils/git.py +137 -0
- ultralytics/utils/instance.py +105 -120
- ultralytics/utils/logger.py +404 -0
- ultralytics/utils/loss.py +99 -61
- ultralytics/utils/metrics.py +649 -478
- ultralytics/utils/nms.py +337 -0
- ultralytics/utils/ops.py +263 -451
- ultralytics/utils/patches.py +70 -31
- ultralytics/utils/plotting.py +253 -223
- ultralytics/utils/tal.py +48 -61
- ultralytics/utils/torch_utils.py +244 -251
- ultralytics/utils/tqdm.py +438 -0
- ultralytics/utils/triton.py +22 -23
- ultralytics/utils/tuner.py +11 -10
- dgenerate_ultralytics_headless-8.3.137.dist-info/RECORD +0 -272
- {dgenerate_ultralytics_headless-8.3.137.dist-info → dgenerate_ultralytics_headless-8.3.224.dist-info}/entry_points.txt +0 -0
- {dgenerate_ultralytics_headless-8.3.137.dist-info → dgenerate_ultralytics_headless-8.3.224.dist-info}/licenses/LICENSE +0 -0
- {dgenerate_ultralytics_headless-8.3.137.dist-info → dgenerate_ultralytics_headless-8.3.224.dist-info}/top_level.txt +0 -0
ultralytics/data/base.py
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
|
|
2
2
|
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
3
5
|
import glob
|
|
4
6
|
import math
|
|
5
7
|
import os
|
|
@@ -7,7 +9,7 @@ import random
|
|
|
7
9
|
from copy import deepcopy
|
|
8
10
|
from multiprocessing.pool import ThreadPool
|
|
9
11
|
from pathlib import Path
|
|
10
|
-
from typing import
|
|
12
|
+
from typing import Any
|
|
11
13
|
|
|
12
14
|
import cv2
|
|
13
15
|
import numpy as np
|
|
@@ -19,11 +21,10 @@ from ultralytics.utils.patches import imread
|
|
|
19
21
|
|
|
20
22
|
|
|
21
23
|
class BaseDataset(Dataset):
|
|
22
|
-
"""
|
|
23
|
-
Base dataset class for loading and processing image data.
|
|
24
|
+
"""Base dataset class for loading and processing image data.
|
|
24
25
|
|
|
25
|
-
This class provides core functionality for loading images, caching, and preparing data for training and inference
|
|
26
|
-
|
|
26
|
+
This class provides core functionality for loading images, caching, and preparing data for training and inference in
|
|
27
|
+
object detection tasks.
|
|
27
28
|
|
|
28
29
|
Attributes:
|
|
29
30
|
img_path (str): Path to the folder containing images.
|
|
@@ -32,9 +33,10 @@ class BaseDataset(Dataset):
|
|
|
32
33
|
single_cls (bool): Whether to treat all objects as a single class.
|
|
33
34
|
prefix (str): Prefix to print in log messages.
|
|
34
35
|
fraction (float): Fraction of dataset to utilize.
|
|
36
|
+
channels (int): Number of channels in the images (1 for grayscale, 3 for RGB).
|
|
35
37
|
cv2_flag (int): OpenCV flag for reading images.
|
|
36
|
-
im_files (
|
|
37
|
-
labels (
|
|
38
|
+
im_files (list[str]): List of image file paths.
|
|
39
|
+
labels (list[dict]): List of label data dictionaries.
|
|
38
40
|
ni (int): Number of images in the dataset.
|
|
39
41
|
rect (bool): Whether to use rectangular training.
|
|
40
42
|
batch_size (int): Size of batches.
|
|
@@ -45,9 +47,11 @@ class BaseDataset(Dataset):
|
|
|
45
47
|
ims (list): List of loaded images.
|
|
46
48
|
im_hw0 (list): List of original image dimensions (h, w).
|
|
47
49
|
im_hw (list): List of resized image dimensions (h, w).
|
|
48
|
-
npy_files (
|
|
50
|
+
npy_files (list[Path]): List of numpy file paths.
|
|
49
51
|
cache (str): Cache images to RAM or disk during training.
|
|
50
52
|
transforms (callable): Image transformation function.
|
|
53
|
+
batch_shapes (np.ndarray): Batch shapes for rectangular training.
|
|
54
|
+
batch (np.ndarray): Batch index of each image.
|
|
51
55
|
|
|
52
56
|
Methods:
|
|
53
57
|
get_img_files: Read image files from the specified path.
|
|
@@ -66,39 +70,38 @@ class BaseDataset(Dataset):
|
|
|
66
70
|
|
|
67
71
|
def __init__(
|
|
68
72
|
self,
|
|
69
|
-
img_path,
|
|
70
|
-
imgsz=640,
|
|
71
|
-
cache=False,
|
|
72
|
-
augment=True,
|
|
73
|
-
hyp=DEFAULT_CFG,
|
|
74
|
-
prefix="",
|
|
75
|
-
rect=False,
|
|
76
|
-
batch_size=16,
|
|
77
|
-
stride=32,
|
|
78
|
-
pad=0.5,
|
|
79
|
-
single_cls=False,
|
|
80
|
-
classes=None,
|
|
81
|
-
fraction=1.0,
|
|
82
|
-
channels=3,
|
|
73
|
+
img_path: str | list[str],
|
|
74
|
+
imgsz: int = 640,
|
|
75
|
+
cache: bool | str = False,
|
|
76
|
+
augment: bool = True,
|
|
77
|
+
hyp: dict[str, Any] = DEFAULT_CFG,
|
|
78
|
+
prefix: str = "",
|
|
79
|
+
rect: bool = False,
|
|
80
|
+
batch_size: int = 16,
|
|
81
|
+
stride: int = 32,
|
|
82
|
+
pad: float = 0.5,
|
|
83
|
+
single_cls: bool = False,
|
|
84
|
+
classes: list[int] | None = None,
|
|
85
|
+
fraction: float = 1.0,
|
|
86
|
+
channels: int = 3,
|
|
83
87
|
):
|
|
84
|
-
"""
|
|
85
|
-
Initialize BaseDataset with given configuration and options.
|
|
88
|
+
"""Initialize BaseDataset with given configuration and options.
|
|
86
89
|
|
|
87
90
|
Args:
|
|
88
|
-
img_path (str): Path to the folder containing images.
|
|
89
|
-
imgsz (int
|
|
90
|
-
cache (bool | str
|
|
91
|
-
augment (bool
|
|
92
|
-
hyp (dict,
|
|
93
|
-
prefix (str
|
|
94
|
-
rect (bool
|
|
95
|
-
batch_size (int
|
|
96
|
-
stride (int
|
|
97
|
-
pad (float
|
|
98
|
-
single_cls (bool
|
|
99
|
-
classes (list, optional): List of included classes.
|
|
100
|
-
fraction (float
|
|
101
|
-
channels (int
|
|
91
|
+
img_path (str | list[str]): Path to the folder containing images or list of image paths.
|
|
92
|
+
imgsz (int): Image size for resizing.
|
|
93
|
+
cache (bool | str): Cache images to RAM or disk during training.
|
|
94
|
+
augment (bool): If True, data augmentation is applied.
|
|
95
|
+
hyp (dict[str, Any]): Hyperparameters to apply data augmentation.
|
|
96
|
+
prefix (str): Prefix to print in log messages.
|
|
97
|
+
rect (bool): If True, rectangular training is used.
|
|
98
|
+
batch_size (int): Size of batches.
|
|
99
|
+
stride (int): Stride used in the model.
|
|
100
|
+
pad (float): Padding value.
|
|
101
|
+
single_cls (bool): If True, single class training is used.
|
|
102
|
+
classes (list[int], optional): List of included classes.
|
|
103
|
+
fraction (float): Fraction of dataset to utilize.
|
|
104
|
+
channels (int): Number of channels in the images (1 for grayscale, 3 for RGB).
|
|
102
105
|
"""
|
|
103
106
|
super().__init__()
|
|
104
107
|
self.img_path = img_path
|
|
@@ -142,15 +145,14 @@ class BaseDataset(Dataset):
|
|
|
142
145
|
# Transforms
|
|
143
146
|
self.transforms = self.build_transforms(hyp=hyp)
|
|
144
147
|
|
|
145
|
-
def get_img_files(self, img_path):
|
|
146
|
-
"""
|
|
147
|
-
Read image files from the specified path.
|
|
148
|
+
def get_img_files(self, img_path: str | list[str]) -> list[str]:
|
|
149
|
+
"""Read image files from the specified path.
|
|
148
150
|
|
|
149
151
|
Args:
|
|
150
|
-
img_path (str |
|
|
152
|
+
img_path (str | list[str]): Path or list of paths to image directories or files.
|
|
151
153
|
|
|
152
154
|
Returns:
|
|
153
|
-
(
|
|
155
|
+
(list[str]): List of image file paths.
|
|
154
156
|
|
|
155
157
|
Raises:
|
|
156
158
|
FileNotFoundError: If no images are found or the path doesn't exist.
|
|
@@ -170,7 +172,7 @@ class BaseDataset(Dataset):
|
|
|
170
172
|
# F += [p.parent / x.lstrip(os.sep) for x in t] # local to global path (pathlib)
|
|
171
173
|
else:
|
|
172
174
|
raise FileNotFoundError(f"{self.prefix}{p} does not exist")
|
|
173
|
-
im_files = sorted(x.replace("/", os.sep) for x in f if x.
|
|
175
|
+
im_files = sorted(x.replace("/", os.sep) for x in f if x.rpartition(".")[-1].lower() in IMG_FORMATS)
|
|
174
176
|
# self.img_files = sorted([x for x in f if x.suffix[1:].lower() in IMG_FORMATS]) # pathlib
|
|
175
177
|
assert im_files, f"{self.prefix}No images found in {img_path}. {FORMATS_HELP_MSG}"
|
|
176
178
|
except Exception as e:
|
|
@@ -180,12 +182,11 @@ class BaseDataset(Dataset):
|
|
|
180
182
|
check_file_speeds(im_files, prefix=self.prefix) # check image read speeds
|
|
181
183
|
return im_files
|
|
182
184
|
|
|
183
|
-
def update_labels(self, include_class:
|
|
184
|
-
"""
|
|
185
|
-
Update labels to include only specified classes.
|
|
185
|
+
def update_labels(self, include_class: list[int] | None) -> None:
|
|
186
|
+
"""Update labels to include only specified classes.
|
|
186
187
|
|
|
187
188
|
Args:
|
|
188
|
-
include_class (list, optional): List of classes to include. If None, all classes are included.
|
|
189
|
+
include_class (list[int], optional): List of classes to include. If None, all classes are included.
|
|
189
190
|
"""
|
|
190
191
|
include_class_array = np.array(include_class).reshape(1, -1)
|
|
191
192
|
for i in range(len(self.labels)):
|
|
@@ -204,18 +205,17 @@ class BaseDataset(Dataset):
|
|
|
204
205
|
if self.single_cls:
|
|
205
206
|
self.labels[i]["cls"][:, 0] = 0
|
|
206
207
|
|
|
207
|
-
def load_image(self, i, rect_mode=True):
|
|
208
|
-
"""
|
|
209
|
-
Load an image from dataset index 'i'.
|
|
208
|
+
def load_image(self, i: int, rect_mode: bool = True) -> tuple[np.ndarray, tuple[int, int], tuple[int, int]]:
|
|
209
|
+
"""Load an image from dataset index 'i'.
|
|
210
210
|
|
|
211
211
|
Args:
|
|
212
212
|
i (int): Index of the image to load.
|
|
213
|
-
rect_mode (bool
|
|
213
|
+
rect_mode (bool): Whether to use rectangular resizing.
|
|
214
214
|
|
|
215
215
|
Returns:
|
|
216
|
-
(np.ndarray): Loaded image as a NumPy array.
|
|
217
|
-
(
|
|
218
|
-
(
|
|
216
|
+
im (np.ndarray): Loaded image as a NumPy array.
|
|
217
|
+
hw_original (tuple[int, int]): Original image dimensions in (height, width) format.
|
|
218
|
+
hw_resized (tuple[int, int]): Resized image dimensions in (height, width) format.
|
|
219
219
|
|
|
220
220
|
Raises:
|
|
221
221
|
FileNotFoundError: If the image file is not found.
|
|
@@ -258,7 +258,7 @@ class BaseDataset(Dataset):
|
|
|
258
258
|
|
|
259
259
|
return self.ims[i], self.im_hw0[i], self.im_hw[i]
|
|
260
260
|
|
|
261
|
-
def cache_images(self):
|
|
261
|
+
def cache_images(self) -> None:
|
|
262
262
|
"""Cache images to memory or disk for faster training."""
|
|
263
263
|
b, gb = 0, 1 << 30 # bytes of cached images, bytes per gigabytes
|
|
264
264
|
fcn, storage = (self.cache_images_to_disk, "Disk") if self.cache == "disk" else (self.load_image, "RAM")
|
|
@@ -274,18 +274,17 @@ class BaseDataset(Dataset):
|
|
|
274
274
|
pbar.desc = f"{self.prefix}Caching images ({b / gb:.1f}GB {storage})"
|
|
275
275
|
pbar.close()
|
|
276
276
|
|
|
277
|
-
def cache_images_to_disk(self, i):
|
|
277
|
+
def cache_images_to_disk(self, i: int) -> None:
|
|
278
278
|
"""Save an image as an *.npy file for faster loading."""
|
|
279
279
|
f = self.npy_files[i]
|
|
280
280
|
if not f.exists():
|
|
281
281
|
np.save(f.as_posix(), imread(self.im_files[i]), allow_pickle=False)
|
|
282
282
|
|
|
283
|
-
def check_cache_disk(self, safety_margin=0.5):
|
|
284
|
-
"""
|
|
285
|
-
Check if there's enough disk space for caching images.
|
|
283
|
+
def check_cache_disk(self, safety_margin: float = 0.5) -> bool:
|
|
284
|
+
"""Check if there's enough disk space for caching images.
|
|
286
285
|
|
|
287
286
|
Args:
|
|
288
|
-
safety_margin (float
|
|
287
|
+
safety_margin (float): Safety margin factor for disk space calculation.
|
|
289
288
|
|
|
290
289
|
Returns:
|
|
291
290
|
(bool): True if there's enough disk space, False otherwise.
|
|
@@ -302,10 +301,10 @@ class BaseDataset(Dataset):
|
|
|
302
301
|
b += im.nbytes
|
|
303
302
|
if not os.access(Path(im_file).parent, os.W_OK):
|
|
304
303
|
self.cache = None
|
|
305
|
-
LOGGER.warning(f"{self.prefix}Skipping caching images to disk, directory not
|
|
304
|
+
LOGGER.warning(f"{self.prefix}Skipping caching images to disk, directory not writable")
|
|
306
305
|
return False
|
|
307
306
|
disk_required = b * self.ni / n * (1 + safety_margin) # bytes required to cache dataset to disk
|
|
308
|
-
total,
|
|
307
|
+
total, _used, free = shutil.disk_usage(Path(self.im_files[0]).parent)
|
|
309
308
|
if disk_required > free:
|
|
310
309
|
self.cache = None
|
|
311
310
|
LOGGER.warning(
|
|
@@ -316,12 +315,11 @@ class BaseDataset(Dataset):
|
|
|
316
315
|
return False
|
|
317
316
|
return True
|
|
318
317
|
|
|
319
|
-
def check_cache_ram(self, safety_margin=0.5):
|
|
320
|
-
"""
|
|
321
|
-
Check if there's enough RAM for caching images.
|
|
318
|
+
def check_cache_ram(self, safety_margin: float = 0.5) -> bool:
|
|
319
|
+
"""Check if there's enough RAM for caching images.
|
|
322
320
|
|
|
323
321
|
Args:
|
|
324
|
-
safety_margin (float
|
|
322
|
+
safety_margin (float): Safety margin factor for RAM calculation.
|
|
325
323
|
|
|
326
324
|
Returns:
|
|
327
325
|
(bool): True if there's enough RAM, False otherwise.
|
|
@@ -346,7 +344,7 @@ class BaseDataset(Dataset):
|
|
|
346
344
|
return False
|
|
347
345
|
return True
|
|
348
346
|
|
|
349
|
-
def set_rectangle(self):
|
|
347
|
+
def set_rectangle(self) -> None:
|
|
350
348
|
"""Set the shape of bounding boxes for YOLO detections as rectangles."""
|
|
351
349
|
bi = np.floor(np.arange(self.ni) / self.batch_size).astype(int) # batch index
|
|
352
350
|
nb = bi[-1] + 1 # number of batches
|
|
@@ -371,19 +369,18 @@ class BaseDataset(Dataset):
|
|
|
371
369
|
self.batch_shapes = np.ceil(np.array(shapes) * self.imgsz / self.stride + self.pad).astype(int) * self.stride
|
|
372
370
|
self.batch = bi # batch index of image
|
|
373
371
|
|
|
374
|
-
def __getitem__(self, index):
|
|
372
|
+
def __getitem__(self, index: int) -> dict[str, Any]:
|
|
375
373
|
"""Return transformed label information for given index."""
|
|
376
374
|
return self.transforms(self.get_image_and_label(index))
|
|
377
375
|
|
|
378
|
-
def get_image_and_label(self, index):
|
|
379
|
-
"""
|
|
380
|
-
Get and return label information from the dataset.
|
|
376
|
+
def get_image_and_label(self, index: int) -> dict[str, Any]:
|
|
377
|
+
"""Get and return label information from the dataset.
|
|
381
378
|
|
|
382
379
|
Args:
|
|
383
380
|
index (int): Index of the image to retrieve.
|
|
384
381
|
|
|
385
382
|
Returns:
|
|
386
|
-
(dict): Label dictionary with image and metadata.
|
|
383
|
+
(dict[str, Any]): Label dictionary with image and metadata.
|
|
387
384
|
"""
|
|
388
385
|
label = deepcopy(self.labels[index]) # requires deepcopy() https://github.com/ultralytics/ultralytics/pull/1948
|
|
389
386
|
label.pop("shape", None) # shape is for rect, remove it
|
|
@@ -396,17 +393,16 @@ class BaseDataset(Dataset):
|
|
|
396
393
|
label["rect_shape"] = self.batch_shapes[self.batch[index]]
|
|
397
394
|
return self.update_labels_info(label)
|
|
398
395
|
|
|
399
|
-
def __len__(self):
|
|
396
|
+
def __len__(self) -> int:
|
|
400
397
|
"""Return the length of the labels list for the dataset."""
|
|
401
398
|
return len(self.labels)
|
|
402
399
|
|
|
403
|
-
def update_labels_info(self, label):
|
|
400
|
+
def update_labels_info(self, label: dict[str, Any]) -> dict[str, Any]:
|
|
404
401
|
"""Custom your label format here."""
|
|
405
402
|
return label
|
|
406
403
|
|
|
407
|
-
def build_transforms(self, hyp=None):
|
|
408
|
-
"""
|
|
409
|
-
Users can customize augmentations here.
|
|
404
|
+
def build_transforms(self, hyp: dict[str, Any] | None = None):
|
|
405
|
+
"""Users can customize augmentations here.
|
|
410
406
|
|
|
411
407
|
Examples:
|
|
412
408
|
>>> if self.augment:
|
|
@@ -418,9 +414,8 @@ class BaseDataset(Dataset):
|
|
|
418
414
|
"""
|
|
419
415
|
raise NotImplementedError
|
|
420
416
|
|
|
421
|
-
def get_labels(self):
|
|
422
|
-
"""
|
|
423
|
-
Users can customize their own format here.
|
|
417
|
+
def get_labels(self) -> list[dict[str, Any]]:
|
|
418
|
+
"""Users can customize their own format here.
|
|
424
419
|
|
|
425
420
|
Examples:
|
|
426
421
|
Ensure output is a dictionary with the following keys:
|