ultralytics 8.3.30__py3-none-any.whl → 8.3.31__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.
- ultralytics/__init__.py +1 -1
- ultralytics/engine/trainer.py +11 -6
- ultralytics/models/yolo/detect/train.py +7 -0
- ultralytics/utils/autobatch.py +8 -4
- ultralytics/utils/tal.py +2 -0
- ultralytics/utils/torch_utils.py +9 -1
- {ultralytics-8.3.30.dist-info → ultralytics-8.3.31.dist-info}/METADATA +1 -1
- {ultralytics-8.3.30.dist-info → ultralytics-8.3.31.dist-info}/RECORD +12 -12
- {ultralytics-8.3.30.dist-info → ultralytics-8.3.31.dist-info}/LICENSE +0 -0
- {ultralytics-8.3.30.dist-info → ultralytics-8.3.31.dist-info}/WHEEL +0 -0
- {ultralytics-8.3.30.dist-info → ultralytics-8.3.31.dist-info}/entry_points.txt +0 -0
- {ultralytics-8.3.30.dist-info → ultralytics-8.3.31.dist-info}/top_level.txt +0 -0
ultralytics/__init__.py
CHANGED
ultralytics/engine/trainer.py
CHANGED
@@ -279,12 +279,7 @@ class BaseTrainer:
|
|
279
279
|
|
280
280
|
# Batch size
|
281
281
|
if self.batch_size < 1 and RANK == -1: # single-GPU only, estimate best batch size
|
282
|
-
self.args.batch = self.batch_size =
|
283
|
-
model=self.model,
|
284
|
-
imgsz=self.args.imgsz,
|
285
|
-
amp=self.amp,
|
286
|
-
batch=self.batch_size,
|
287
|
-
)
|
282
|
+
self.args.batch = self.batch_size = self.auto_batch()
|
288
283
|
|
289
284
|
# Dataloaders
|
290
285
|
batch_size = self.batch_size // max(world_size, 1)
|
@@ -478,6 +473,16 @@ class BaseTrainer:
|
|
478
473
|
self._clear_memory()
|
479
474
|
self.run_callbacks("teardown")
|
480
475
|
|
476
|
+
def auto_batch(self, max_num_obj=0):
|
477
|
+
"""Get batch size by calculating memory occupation of model."""
|
478
|
+
return check_train_batch_size(
|
479
|
+
model=self.model,
|
480
|
+
imgsz=self.args.imgsz,
|
481
|
+
amp=self.amp,
|
482
|
+
batch=self.batch_size,
|
483
|
+
max_num_obj=max_num_obj,
|
484
|
+
) # returns batch size
|
485
|
+
|
481
486
|
def _get_memory(self):
|
482
487
|
"""Get accelerator memory utilization in GB."""
|
483
488
|
if self.device.type == "mps":
|
@@ -141,3 +141,10 @@ class DetectionTrainer(BaseTrainer):
|
|
141
141
|
boxes = np.concatenate([lb["bboxes"] for lb in self.train_loader.dataset.labels], 0)
|
142
142
|
cls = np.concatenate([lb["cls"] for lb in self.train_loader.dataset.labels], 0)
|
143
143
|
plot_labels(boxes, cls.squeeze(), names=self.data["names"], save_dir=self.save_dir, on_plot=self.on_plot)
|
144
|
+
|
145
|
+
def auto_batch(self):
|
146
|
+
"""Get batch size by calculating memory occupation of model."""
|
147
|
+
train_dataset = self.build_dataset(self.trainset, mode="train", batch=16)
|
148
|
+
# 4 for mosaic augmentation
|
149
|
+
max_num_obj = max(len(l["cls"]) for l in train_dataset.labels) * 4
|
150
|
+
return super().auto_batch(max_num_obj)
|
ultralytics/utils/autobatch.py
CHANGED
@@ -11,7 +11,7 @@ from ultralytics.utils import DEFAULT_CFG, LOGGER, colorstr
|
|
11
11
|
from ultralytics.utils.torch_utils import autocast, profile
|
12
12
|
|
13
13
|
|
14
|
-
def check_train_batch_size(model, imgsz=640, amp=True, batch=-1):
|
14
|
+
def check_train_batch_size(model, imgsz=640, amp=True, batch=-1, max_num_obj=1):
|
15
15
|
"""
|
16
16
|
Compute optimal YOLO training batch size using the autobatch() function.
|
17
17
|
|
@@ -20,6 +20,7 @@ def check_train_batch_size(model, imgsz=640, amp=True, batch=-1):
|
|
20
20
|
imgsz (int, optional): Image size used for training.
|
21
21
|
amp (bool, optional): Use automatic mixed precision if True.
|
22
22
|
batch (float, optional): Fraction of GPU memory to use. If -1, use default.
|
23
|
+
max_num_obj (int, optional): The maximum number of objects from dataset.
|
23
24
|
|
24
25
|
Returns:
|
25
26
|
(int): Optimal batch size computed using the autobatch() function.
|
@@ -29,10 +30,12 @@ def check_train_batch_size(model, imgsz=640, amp=True, batch=-1):
|
|
29
30
|
Otherwise, a default fraction of 0.6 is used.
|
30
31
|
"""
|
31
32
|
with autocast(enabled=amp):
|
32
|
-
return autobatch(
|
33
|
+
return autobatch(
|
34
|
+
deepcopy(model).train(), imgsz, fraction=batch if 0.0 < batch < 1.0 else 0.6, max_num_obj=max_num_obj
|
35
|
+
)
|
33
36
|
|
34
37
|
|
35
|
-
def autobatch(model, imgsz=640, fraction=0.60, batch_size=DEFAULT_CFG.batch):
|
38
|
+
def autobatch(model, imgsz=640, fraction=0.60, batch_size=DEFAULT_CFG.batch, max_num_obj=1):
|
36
39
|
"""
|
37
40
|
Automatically estimate the best YOLO batch size to use a fraction of the available CUDA memory.
|
38
41
|
|
@@ -41,6 +44,7 @@ def autobatch(model, imgsz=640, fraction=0.60, batch_size=DEFAULT_CFG.batch):
|
|
41
44
|
imgsz (int, optional): The image size used as input for the YOLO model. Defaults to 640.
|
42
45
|
fraction (float, optional): The fraction of available CUDA memory to use. Defaults to 0.60.
|
43
46
|
batch_size (int, optional): The default batch size to use if an error is detected. Defaults to 16.
|
47
|
+
max_num_obj (int, optional): The maximum number of objects from dataset.
|
44
48
|
|
45
49
|
Returns:
|
46
50
|
(int): The optimal batch size.
|
@@ -70,7 +74,7 @@ def autobatch(model, imgsz=640, fraction=0.60, batch_size=DEFAULT_CFG.batch):
|
|
70
74
|
batch_sizes = [1, 2, 4, 8, 16] if t < 16 else [1, 2, 4, 8, 16, 32, 64]
|
71
75
|
try:
|
72
76
|
img = [torch.empty(b, 3, imgsz, imgsz) for b in batch_sizes]
|
73
|
-
results = profile(img, model, n=1, device=device)
|
77
|
+
results = profile(img, model, n=1, device=device, max_num_obj=max_num_obj)
|
74
78
|
|
75
79
|
# Fit a solution
|
76
80
|
y = [x[2] for x in results if x] # memory [2]
|
ultralytics/utils/tal.py
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
import torch
|
4
4
|
import torch.nn as nn
|
5
5
|
|
6
|
+
from . import LOGGER
|
6
7
|
from .checks import check_version
|
7
8
|
from .metrics import bbox_iou, probiou
|
8
9
|
from .ops import xywhr2xyxyxyxy
|
@@ -73,6 +74,7 @@ class TaskAlignedAssigner(nn.Module):
|
|
73
74
|
return self._forward(pd_scores, pd_bboxes, anc_points, gt_labels, gt_bboxes, mask_gt)
|
74
75
|
except torch.OutOfMemoryError:
|
75
76
|
# Move tensors to CPU, compute, then move back to original device
|
77
|
+
LOGGER.warning("WARNING: CUDA OutOfMemoryError in TaskAlignedAssigner, using CPU")
|
76
78
|
cpu_tensors = [t.cpu() for t in (pd_scores, pd_bboxes, anc_points, gt_labels, gt_bboxes, mask_gt)]
|
77
79
|
result = self._forward(*cpu_tensors)
|
78
80
|
return tuple(t.to(device) for t in result)
|
ultralytics/utils/torch_utils.py
CHANGED
@@ -623,7 +623,7 @@ def convert_optimizer_state_dict_to_fp16(state_dict):
|
|
623
623
|
return state_dict
|
624
624
|
|
625
625
|
|
626
|
-
def profile(input, ops, n=10, device=None):
|
626
|
+
def profile(input, ops, n=10, device=None, max_num_obj=0):
|
627
627
|
"""
|
628
628
|
Ultralytics speed, memory and FLOPs profiler.
|
629
629
|
|
@@ -671,6 +671,14 @@ def profile(input, ops, n=10, device=None):
|
|
671
671
|
t[2] = float("nan")
|
672
672
|
tf += (t[1] - t[0]) * 1000 / n # ms per op forward
|
673
673
|
tb += (t[2] - t[1]) * 1000 / n # ms per op backward
|
674
|
+
if max_num_obj: # simulate training with predictions per image grid (for AutoBatch)
|
675
|
+
torch.randn(
|
676
|
+
x.shape[0],
|
677
|
+
max_num_obj,
|
678
|
+
int(sum([(x.shape[-1] / s) * (x.shape[-2] / s) for s in m.stride.tolist()])),
|
679
|
+
device=device,
|
680
|
+
dtype=torch.float32,
|
681
|
+
)
|
674
682
|
mem = torch.cuda.memory_reserved() / 1e9 if torch.cuda.is_available() else 0 # (GB)
|
675
683
|
s_in, s_out = (tuple(x.shape) if isinstance(x, torch.Tensor) else "list" for x in (x, y)) # shapes
|
676
684
|
p = sum(x.numel() for x in m.parameters()) if isinstance(m, nn.Module) else 0 # parameters
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: ultralytics
|
3
|
-
Version: 8.3.
|
3
|
+
Version: 8.3.31
|
4
4
|
Summary: Ultralytics YOLO 🚀 for SOTA object detection, multi-object tracking, instance segmentation, pose estimation and image classification.
|
5
5
|
Author-email: Glenn Jocher <glenn.jocher@ultralytics.com>, Jing Qiu <jing.qiu@ultralytics.com>
|
6
6
|
Maintainer-email: Ultralytics <hello@ultralytics.com>
|
@@ -7,7 +7,7 @@ tests/test_exports.py,sha256=1MvhcQ2qHdbJImHII-bFarcaIcm-kPlEK-OdFLxnj7o,8769
|
|
7
7
|
tests/test_integrations.py,sha256=f5-QCUk1SU_-qn4mBCZwS3GN3tXEBIIXo4z2EhExbHw,6126
|
8
8
|
tests/test_python.py,sha256=I1RRdCwLdrc3jX06huVxct8HX8ccQOmQgVpuEflRl0U,23560
|
9
9
|
tests/test_solutions.py,sha256=sPYhy2d814mIVvojQeVxeZPu0IVy01_Y8zuMcu_9GF0,3790
|
10
|
-
ultralytics/__init__.py,sha256=
|
10
|
+
ultralytics/__init__.py,sha256=Z3VjR0LGu2YpNK8RouNCLcCrmcAaslU5opcp7PtMzsg,681
|
11
11
|
ultralytics/assets/bus.jpg,sha256=wCAZxJecGR63Od3ZRERe9Aja1Weayrb9Ug751DS_vGM,137419
|
12
12
|
ultralytics/assets/zidane.jpg,sha256=Ftc4aeMmen1O0A3o6GCDO9FlfBslLpTAw0gnetx7bts,50427
|
13
13
|
ultralytics/cfg/__init__.py,sha256=ArJow4-pOPN3y6aKOv5KcVXimikI6vAQvQlSRb7IdWE,38743
|
@@ -103,7 +103,7 @@ ultralytics/engine/exporter.py,sha256=DH67LwNDr3fiWxaES-lhSLvm5pCuasXLbQv4FSLCi_
|
|
103
103
|
ultralytics/engine/model.py,sha256=TfuTczFjNJ3GW0E_qWVH6OaJ_2I-_Srx7i_4GQebDoo,51472
|
104
104
|
ultralytics/engine/predictor.py,sha256=aS4yJdTK2kYq-TTpzIlWxqnAcBz38zIECZoMb_yOPMY,17597
|
105
105
|
ultralytics/engine/results.py,sha256=a1XFZRPwqgKDBOEAibHuT9nP2xefLiWVsMoBJbcr4iA,75058
|
106
|
-
ultralytics/engine/trainer.py,sha256=
|
106
|
+
ultralytics/engine/trainer.py,sha256=Cd95QLJ3C4fncoOX1YgauLA9aWVYRd1G6x0Au2xX86k,37335
|
107
107
|
ultralytics/engine/tuner.py,sha256=WBj8iw1K1TK0hvanlA-wkwmfqh1SI8jEe2dGwUINeTg,11838
|
108
108
|
ultralytics/engine/validator.py,sha256=aWpXE3nrOqaA7jCuUgwxi0FabiGTIXtZvjoJyCX903o,14870
|
109
109
|
ultralytics/hub/__init__.py,sha256=c6Me4E8V-P7mtzTggyPYz9FnVkqWRyPp9F-fMcyFNQ0,5632
|
@@ -151,7 +151,7 @@ ultralytics/models/yolo/classify/train.py,sha256=3aYzLDqX_03xR1xqlTn1TxA4t58cCIG
|
|
151
151
|
ultralytics/models/yolo/classify/val.py,sha256=Tzizhp3ebzPvwJejrE8tb-TuXw4MdkEI9mOANV74eXQ,4909
|
152
152
|
ultralytics/models/yolo/detect/__init__.py,sha256=JR8gZJWn7wMBbh-0j_073nxJVZTMFZVWTOG5Wnvk6w0,229
|
153
153
|
ultralytics/models/yolo/detect/predict.py,sha256=-uZFLutxGYZX47RANcaxC-LFStRbv0nBv_8-ypadQoI,1471
|
154
|
-
ultralytics/models/yolo/detect/train.py,sha256=
|
154
|
+
ultralytics/models/yolo/detect/train.py,sha256=f-QwAxaRsdtY-KY9femcWLQt1wB1tAHu-QV0a13LOGA,6702
|
155
155
|
ultralytics/models/yolo/detect/val.py,sha256=Ydf0W7FPf-nSz_lOCTcIrlDqhG_kOK8Od6eYsGQDx9U,15144
|
156
156
|
ultralytics/models/yolo/obb/__init__.py,sha256=txWbPGLY1_M7ZwlLQjrwGjTBOlsv9P3yk5ZEgysTinU,193
|
157
157
|
ultralytics/models/yolo/obb/predict.py,sha256=VxpKCKV5dWnOr0GyV1rJGH5SzzRouCYW_8T26xJ8MU8,2037
|
@@ -200,7 +200,7 @@ ultralytics/trackers/utils/gmc.py,sha256=VcURuY041qGCeWUGMxHZBr10T16LtcMqyv7AmTf
|
|
200
200
|
ultralytics/trackers/utils/kalman_filter.py,sha256=cH9zD3fwkuezP97H9mw8cSBN7a8hHKx_Sx1j7t3oYGs,21349
|
201
201
|
ultralytics/trackers/utils/matching.py,sha256=3Ie1WNNRZ4_q3365F03XD7Nr9juZB_08mw4yUKC3w74,7162
|
202
202
|
ultralytics/utils/__init__.py,sha256=08pFkzKn1eR9xdIFhx8tx_8MO-gqXjt2n0HGwDeUlWE,49159
|
203
|
-
ultralytics/utils/autobatch.py,sha256=
|
203
|
+
ultralytics/utils/autobatch.py,sha256=nt0nSNNhrQqvtaxeNBBYpU2OkZnI3ihNEAa3jF4pybo,4594
|
204
204
|
ultralytics/utils/benchmarks.py,sha256=aEW28iVIMj-8bwOgISDphOJExDmaGi5bz3G2PJlRjcc,25793
|
205
205
|
ultralytics/utils/checks.py,sha256=KXQSeauhzecy9tSjyDVy8oXbTDkHSSB9lOTYrqRWpok,29582
|
206
206
|
ultralytics/utils/dist.py,sha256=NDFga-uKxkBX2zLxFHSene_cCiGQJoyOeCXcN9JIOIk,2358
|
@@ -213,8 +213,8 @@ ultralytics/utils/metrics.py,sha256=msPaXc244ndc0NPBhnNlHsKkVhdc-TMgFn5NATlZZVI,
|
|
213
213
|
ultralytics/utils/ops.py,sha256=dsXNdyrYx_p6io6zezig9p84dxS7U-10vceHNVu2IL0,32888
|
214
214
|
ultralytics/utils/patches.py,sha256=J-iOwIRbfUs-inBZerhnXby5tUKjYcOIyvhLTS352JE,3270
|
215
215
|
ultralytics/utils/plotting.py,sha256=TKtdbAOl6gZdFD2hlA5T4LNWfr2LUWbCC-cXkgL1JAU,61089
|
216
|
-
ultralytics/utils/tal.py,sha256=
|
217
|
-
ultralytics/utils/torch_utils.py,sha256=
|
216
|
+
ultralytics/utils/tal.py,sha256=thD_AEhVmhaZqmS5szZMvpKO-RKOeZwfX1BYAhdnA0o,18470
|
217
|
+
ultralytics/utils/torch_utils.py,sha256=CfftLVZqCEgIOLtRsU4mytRJoHDiXd5ijzIqIVt-zZM,32070
|
218
218
|
ultralytics/utils/triton.py,sha256=gg1finxno_tY2Ge9PMhmu7PI9wvoFZoiicdT4Bhqv3w,3936
|
219
219
|
ultralytics/utils/tuner.py,sha256=K09-z5k1E4ZriSKoWdwQrJ2PJ2fY1ez3-b2R6aKPTqM,6198
|
220
220
|
ultralytics/utils/callbacks/__init__.py,sha256=YrWqC3BVVaTLob4iCPR6I36mUxIUOpPJW7B_LjT78Qw,214
|
@@ -228,9 +228,9 @@ ultralytics/utils/callbacks/neptune.py,sha256=IbGQfEltamUKXJt93uSLQFn8c2rYh3DMTg
|
|
228
228
|
ultralytics/utils/callbacks/raytune.py,sha256=Ck_yFzg7UZXiDWrLHaltjQybzVWSFDfzpdrx9ZYTRfI,700
|
229
229
|
ultralytics/utils/callbacks/tensorboard.py,sha256=SHlE58Fb-sg-uZKtgy-ybIO3SAIfK55aj8kTYGA0Cyg,4167
|
230
230
|
ultralytics/utils/callbacks/wb.py,sha256=oX3JarCJGhzvW556XiEXQNaZblAaK_UETAt3kzkY61w,6869
|
231
|
-
ultralytics-8.3.
|
232
|
-
ultralytics-8.3.
|
233
|
-
ultralytics-8.3.
|
234
|
-
ultralytics-8.3.
|
235
|
-
ultralytics-8.3.
|
236
|
-
ultralytics-8.3.
|
231
|
+
ultralytics-8.3.31.dist-info/LICENSE,sha256=DZak_2itbUtvHzD3E7GNUYSRK6jdOJ-GqncQ2weavLA,34523
|
232
|
+
ultralytics-8.3.31.dist-info/METADATA,sha256=pCRq3cWOvmofljRT9bsJ0P_x0Mtk2uNQXQUHZf8scO8,35213
|
233
|
+
ultralytics-8.3.31.dist-info/WHEEL,sha256=R06PA3UVYHThwHvxuRWMqaGcr-PuniXahwjmQRFMEkY,91
|
234
|
+
ultralytics-8.3.31.dist-info/entry_points.txt,sha256=YM_wiKyTe9yRrsEfqvYolNO5ngwfoL4-NwgKzc8_7sI,93
|
235
|
+
ultralytics-8.3.31.dist-info/top_level.txt,sha256=XP49TwiMw4QGsvTLSYiJhz1xF_k7ev5mQ8jJXaXi45Q,12
|
236
|
+
ultralytics-8.3.31.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|