dgenerate-ultralytics-headless 8.3.222__py3-none-any.whl → 8.3.225__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.222.dist-info → dgenerate_ultralytics_headless-8.3.225.dist-info}/METADATA +2 -2
- dgenerate_ultralytics_headless-8.3.225.dist-info/RECORD +286 -0
- tests/conftest.py +5 -8
- tests/test_cli.py +1 -8
- tests/test_python.py +1 -2
- ultralytics/__init__.py +1 -1
- ultralytics/cfg/__init__.py +34 -49
- ultralytics/cfg/datasets/ImageNet.yaml +1 -1
- ultralytics/cfg/datasets/kitti.yaml +27 -0
- ultralytics/cfg/datasets/lvis.yaml +5 -5
- ultralytics/cfg/datasets/open-images-v7.yaml +1 -1
- ultralytics/data/annotator.py +3 -4
- ultralytics/data/augment.py +244 -323
- ultralytics/data/base.py +12 -22
- ultralytics/data/build.py +47 -40
- ultralytics/data/converter.py +32 -42
- ultralytics/data/dataset.py +43 -71
- ultralytics/data/loaders.py +22 -34
- ultralytics/data/split.py +5 -6
- ultralytics/data/split_dota.py +8 -15
- ultralytics/data/utils.py +27 -36
- ultralytics/engine/exporter.py +49 -116
- ultralytics/engine/model.py +144 -180
- ultralytics/engine/predictor.py +18 -29
- ultralytics/engine/results.py +165 -231
- ultralytics/engine/trainer.py +11 -19
- ultralytics/engine/tuner.py +13 -23
- ultralytics/engine/validator.py +6 -10
- ultralytics/hub/__init__.py +7 -12
- ultralytics/hub/auth.py +6 -12
- ultralytics/hub/google/__init__.py +7 -10
- ultralytics/hub/session.py +15 -25
- ultralytics/hub/utils.py +3 -6
- ultralytics/models/fastsam/model.py +6 -8
- ultralytics/models/fastsam/predict.py +5 -10
- ultralytics/models/fastsam/utils.py +1 -2
- ultralytics/models/fastsam/val.py +2 -4
- ultralytics/models/nas/model.py +5 -8
- ultralytics/models/nas/predict.py +7 -9
- ultralytics/models/nas/val.py +1 -2
- ultralytics/models/rtdetr/model.py +5 -8
- ultralytics/models/rtdetr/predict.py +15 -18
- ultralytics/models/rtdetr/train.py +10 -13
- ultralytics/models/rtdetr/val.py +13 -20
- ultralytics/models/sam/amg.py +12 -18
- ultralytics/models/sam/build.py +6 -9
- ultralytics/models/sam/model.py +16 -23
- ultralytics/models/sam/modules/blocks.py +62 -84
- ultralytics/models/sam/modules/decoders.py +17 -24
- ultralytics/models/sam/modules/encoders.py +40 -56
- ultralytics/models/sam/modules/memory_attention.py +10 -16
- ultralytics/models/sam/modules/sam.py +41 -47
- ultralytics/models/sam/modules/tiny_encoder.py +64 -83
- ultralytics/models/sam/modules/transformer.py +17 -27
- ultralytics/models/sam/modules/utils.py +31 -42
- ultralytics/models/sam/predict.py +172 -209
- ultralytics/models/utils/loss.py +14 -26
- ultralytics/models/utils/ops.py +13 -17
- ultralytics/models/yolo/classify/predict.py +8 -11
- ultralytics/models/yolo/classify/train.py +8 -16
- ultralytics/models/yolo/classify/val.py +13 -20
- ultralytics/models/yolo/detect/predict.py +4 -8
- ultralytics/models/yolo/detect/train.py +11 -20
- ultralytics/models/yolo/detect/val.py +38 -48
- ultralytics/models/yolo/model.py +35 -47
- ultralytics/models/yolo/obb/predict.py +5 -8
- ultralytics/models/yolo/obb/train.py +11 -14
- ultralytics/models/yolo/obb/val.py +20 -28
- ultralytics/models/yolo/pose/predict.py +5 -8
- ultralytics/models/yolo/pose/train.py +4 -8
- ultralytics/models/yolo/pose/val.py +31 -39
- ultralytics/models/yolo/segment/predict.py +9 -14
- ultralytics/models/yolo/segment/train.py +3 -6
- ultralytics/models/yolo/segment/val.py +16 -26
- ultralytics/models/yolo/world/train.py +8 -14
- ultralytics/models/yolo/world/train_world.py +11 -16
- ultralytics/models/yolo/yoloe/predict.py +16 -23
- ultralytics/models/yolo/yoloe/train.py +30 -43
- ultralytics/models/yolo/yoloe/train_seg.py +5 -10
- ultralytics/models/yolo/yoloe/val.py +15 -20
- ultralytics/nn/autobackend.py +10 -18
- ultralytics/nn/modules/activation.py +4 -6
- ultralytics/nn/modules/block.py +99 -185
- ultralytics/nn/modules/conv.py +45 -90
- ultralytics/nn/modules/head.py +44 -98
- ultralytics/nn/modules/transformer.py +44 -76
- ultralytics/nn/modules/utils.py +14 -19
- ultralytics/nn/tasks.py +86 -146
- ultralytics/nn/text_model.py +25 -40
- ultralytics/solutions/ai_gym.py +10 -16
- ultralytics/solutions/analytics.py +7 -10
- ultralytics/solutions/config.py +4 -5
- ultralytics/solutions/distance_calculation.py +9 -12
- ultralytics/solutions/heatmap.py +7 -13
- ultralytics/solutions/instance_segmentation.py +5 -8
- ultralytics/solutions/object_blurrer.py +7 -10
- ultralytics/solutions/object_counter.py +8 -12
- ultralytics/solutions/object_cropper.py +5 -8
- ultralytics/solutions/parking_management.py +12 -14
- ultralytics/solutions/queue_management.py +4 -6
- ultralytics/solutions/region_counter.py +7 -10
- ultralytics/solutions/security_alarm.py +14 -19
- ultralytics/solutions/similarity_search.py +7 -12
- ultralytics/solutions/solutions.py +31 -53
- ultralytics/solutions/speed_estimation.py +6 -9
- ultralytics/solutions/streamlit_inference.py +2 -4
- ultralytics/solutions/trackzone.py +7 -10
- ultralytics/solutions/vision_eye.py +5 -8
- ultralytics/trackers/basetrack.py +2 -4
- ultralytics/trackers/bot_sort.py +6 -11
- ultralytics/trackers/byte_tracker.py +10 -15
- ultralytics/trackers/track.py +3 -6
- ultralytics/trackers/utils/gmc.py +6 -12
- ultralytics/trackers/utils/kalman_filter.py +35 -43
- ultralytics/trackers/utils/matching.py +6 -10
- ultralytics/utils/__init__.py +61 -100
- ultralytics/utils/autobatch.py +2 -4
- ultralytics/utils/autodevice.py +11 -13
- ultralytics/utils/benchmarks.py +25 -35
- ultralytics/utils/callbacks/base.py +8 -10
- ultralytics/utils/callbacks/clearml.py +2 -4
- ultralytics/utils/callbacks/comet.py +30 -44
- ultralytics/utils/callbacks/dvc.py +13 -18
- ultralytics/utils/callbacks/mlflow.py +4 -5
- ultralytics/utils/callbacks/neptune.py +4 -6
- ultralytics/utils/callbacks/raytune.py +3 -4
- ultralytics/utils/callbacks/tensorboard.py +4 -6
- ultralytics/utils/callbacks/wb.py +10 -13
- ultralytics/utils/checks.py +29 -56
- ultralytics/utils/cpu.py +1 -2
- ultralytics/utils/dist.py +8 -12
- ultralytics/utils/downloads.py +17 -27
- ultralytics/utils/errors.py +6 -8
- ultralytics/utils/events.py +2 -4
- ultralytics/utils/export/__init__.py +4 -239
- ultralytics/utils/export/engine.py +237 -0
- ultralytics/utils/export/imx.py +11 -17
- ultralytics/utils/export/tensorflow.py +217 -0
- ultralytics/utils/files.py +10 -15
- ultralytics/utils/git.py +5 -7
- ultralytics/utils/instance.py +30 -51
- ultralytics/utils/logger.py +11 -15
- ultralytics/utils/loss.py +8 -14
- ultralytics/utils/metrics.py +98 -138
- ultralytics/utils/nms.py +13 -16
- ultralytics/utils/ops.py +47 -74
- ultralytics/utils/patches.py +11 -18
- ultralytics/utils/plotting.py +29 -42
- ultralytics/utils/tal.py +25 -39
- ultralytics/utils/torch_utils.py +45 -73
- ultralytics/utils/tqdm.py +6 -8
- ultralytics/utils/triton.py +9 -12
- ultralytics/utils/tuner.py +1 -2
- dgenerate_ultralytics_headless-8.3.222.dist-info/RECORD +0 -283
- {dgenerate_ultralytics_headless-8.3.222.dist-info → dgenerate_ultralytics_headless-8.3.225.dist-info}/WHEEL +0 -0
- {dgenerate_ultralytics_headless-8.3.222.dist-info → dgenerate_ultralytics_headless-8.3.225.dist-info}/entry_points.txt +0 -0
- {dgenerate_ultralytics_headless-8.3.222.dist-info → dgenerate_ultralytics_headless-8.3.225.dist-info}/licenses/LICENSE +0 -0
- {dgenerate_ultralytics_headless-8.3.222.dist-info → dgenerate_ultralytics_headless-8.3.225.dist-info}/top_level.txt +0 -0
ultralytics/utils/torch_utils.py
CHANGED
|
@@ -83,8 +83,7 @@ def smart_inference_mode():
|
|
|
83
83
|
|
|
84
84
|
|
|
85
85
|
def autocast(enabled: bool, device: str = "cuda"):
|
|
86
|
-
"""
|
|
87
|
-
Get the appropriate autocast context manager based on PyTorch version and AMP setting.
|
|
86
|
+
"""Get the appropriate autocast context manager based on PyTorch version and AMP setting.
|
|
88
87
|
|
|
89
88
|
This function returns a context manager for automatic mixed precision (AMP) training that is compatible with both
|
|
90
89
|
older and newer versions of PyTorch. It handles the differences in the autocast API between PyTorch versions.
|
|
@@ -96,14 +95,14 @@ def autocast(enabled: bool, device: str = "cuda"):
|
|
|
96
95
|
Returns:
|
|
97
96
|
(torch.amp.autocast): The appropriate autocast context manager.
|
|
98
97
|
|
|
99
|
-
Notes:
|
|
100
|
-
- For PyTorch versions 1.13 and newer, it uses `torch.amp.autocast`.
|
|
101
|
-
- For older versions, it uses `torch.cuda.autocast`.
|
|
102
|
-
|
|
103
98
|
Examples:
|
|
104
99
|
>>> with autocast(enabled=True):
|
|
105
100
|
... # Your mixed precision operations here
|
|
106
101
|
... pass
|
|
102
|
+
|
|
103
|
+
Notes:
|
|
104
|
+
- For PyTorch versions 1.13 and newer, it uses `torch.amp.autocast`.
|
|
105
|
+
- For older versions, it uses `torch.cuda.autocast`.
|
|
107
106
|
"""
|
|
108
107
|
if TORCH_1_13:
|
|
109
108
|
return torch.amp.autocast(device, enabled=enabled)
|
|
@@ -132,8 +131,7 @@ def get_gpu_info(index):
|
|
|
132
131
|
|
|
133
132
|
|
|
134
133
|
def select_device(device="", newline=False, verbose=True):
|
|
135
|
-
"""
|
|
136
|
-
Select the appropriate PyTorch device based on the provided arguments.
|
|
134
|
+
"""Select the appropriate PyTorch device based on the provided arguments.
|
|
137
135
|
|
|
138
136
|
The function takes a string specifying the device or a torch.device object and returns a torch.device object
|
|
139
137
|
representing the selected device. The function also validates the number of available devices and raises an
|
|
@@ -236,8 +234,7 @@ def time_sync():
|
|
|
236
234
|
|
|
237
235
|
|
|
238
236
|
def fuse_conv_and_bn(conv, bn):
|
|
239
|
-
"""
|
|
240
|
-
Fuse Conv2d and BatchNorm2d layers for inference optimization.
|
|
237
|
+
"""Fuse Conv2d and BatchNorm2d layers for inference optimization.
|
|
241
238
|
|
|
242
239
|
Args:
|
|
243
240
|
conv (nn.Conv2d): Convolutional layer to fuse.
|
|
@@ -246,7 +243,7 @@ def fuse_conv_and_bn(conv, bn):
|
|
|
246
243
|
Returns:
|
|
247
244
|
(nn.Conv2d): The fused convolutional layer with gradients disabled.
|
|
248
245
|
|
|
249
|
-
|
|
246
|
+
Examples:
|
|
250
247
|
>>> conv = nn.Conv2d(3, 16, 3)
|
|
251
248
|
>>> bn = nn.BatchNorm2d(16)
|
|
252
249
|
>>> fused_conv = fuse_conv_and_bn(conv, bn)
|
|
@@ -270,8 +267,7 @@ def fuse_conv_and_bn(conv, bn):
|
|
|
270
267
|
|
|
271
268
|
|
|
272
269
|
def fuse_deconv_and_bn(deconv, bn):
|
|
273
|
-
"""
|
|
274
|
-
Fuse ConvTranspose2d and BatchNorm2d layers for inference optimization.
|
|
270
|
+
"""Fuse ConvTranspose2d and BatchNorm2d layers for inference optimization.
|
|
275
271
|
|
|
276
272
|
Args:
|
|
277
273
|
deconv (nn.ConvTranspose2d): Transposed convolutional layer to fuse.
|
|
@@ -280,7 +276,7 @@ def fuse_deconv_and_bn(deconv, bn):
|
|
|
280
276
|
Returns:
|
|
281
277
|
(nn.ConvTranspose2d): The fused transposed convolutional layer with gradients disabled.
|
|
282
278
|
|
|
283
|
-
|
|
279
|
+
Examples:
|
|
284
280
|
>>> deconv = nn.ConvTranspose2d(16, 3, 3)
|
|
285
281
|
>>> bn = nn.BatchNorm2d(3)
|
|
286
282
|
>>> fused_deconv = fuse_deconv_and_bn(deconv, bn)
|
|
@@ -304,8 +300,7 @@ def fuse_deconv_and_bn(deconv, bn):
|
|
|
304
300
|
|
|
305
301
|
|
|
306
302
|
def model_info(model, detailed=False, verbose=True, imgsz=640):
|
|
307
|
-
"""
|
|
308
|
-
Print and return detailed model information layer by layer.
|
|
303
|
+
"""Print and return detailed model information layer by layer.
|
|
309
304
|
|
|
310
305
|
Args:
|
|
311
306
|
model (nn.Module): Model to analyze.
|
|
@@ -359,8 +354,7 @@ def get_num_gradients(model):
|
|
|
359
354
|
|
|
360
355
|
|
|
361
356
|
def model_info_for_loggers(trainer):
|
|
362
|
-
"""
|
|
363
|
-
Return model info dict with useful model information.
|
|
357
|
+
"""Return model info dict with useful model information.
|
|
364
358
|
|
|
365
359
|
Args:
|
|
366
360
|
trainer (ultralytics.engine.trainer.BaseTrainer): The trainer object containing model and validation data.
|
|
@@ -393,12 +387,10 @@ def model_info_for_loggers(trainer):
|
|
|
393
387
|
|
|
394
388
|
|
|
395
389
|
def get_flops(model, imgsz=640):
|
|
396
|
-
"""
|
|
397
|
-
Calculate FLOPs (floating point operations) for a model in billions.
|
|
390
|
+
"""Calculate FLOPs (floating point operations) for a model in billions.
|
|
398
391
|
|
|
399
|
-
Attempts two calculation methods: first with a stride-based tensor for efficiency,
|
|
400
|
-
|
|
401
|
-
if thop library is unavailable or calculation fails.
|
|
392
|
+
Attempts two calculation methods: first with a stride-based tensor for efficiency, then falls back to full image
|
|
393
|
+
size if needed (e.g., for RTDETR models). Returns 0.0 if thop library is unavailable or calculation fails.
|
|
402
394
|
|
|
403
395
|
Args:
|
|
404
396
|
model (nn.Module): The model to calculate FLOPs for.
|
|
@@ -435,8 +427,7 @@ def get_flops(model, imgsz=640):
|
|
|
435
427
|
|
|
436
428
|
|
|
437
429
|
def get_flops_with_torch_profiler(model, imgsz=640):
|
|
438
|
-
"""
|
|
439
|
-
Compute model FLOPs using torch profiler (alternative to thop package, but 2-10x slower).
|
|
430
|
+
"""Compute model FLOPs using torch profiler (alternative to thop package, but 2-10x slower).
|
|
440
431
|
|
|
441
432
|
Args:
|
|
442
433
|
model (nn.Module): The model to calculate FLOPs for.
|
|
@@ -482,8 +473,7 @@ def initialize_weights(model):
|
|
|
482
473
|
|
|
483
474
|
|
|
484
475
|
def scale_img(img, ratio=1.0, same_shape=False, gs=32):
|
|
485
|
-
"""
|
|
486
|
-
Scale and pad an image tensor, optionally maintaining aspect ratio and padding to gs multiple.
|
|
476
|
+
"""Scale and pad an image tensor, optionally maintaining aspect ratio and padding to gs multiple.
|
|
487
477
|
|
|
488
478
|
Args:
|
|
489
479
|
img (torch.Tensor): Input image tensor.
|
|
@@ -505,8 +495,7 @@ def scale_img(img, ratio=1.0, same_shape=False, gs=32):
|
|
|
505
495
|
|
|
506
496
|
|
|
507
497
|
def copy_attr(a, b, include=(), exclude=()):
|
|
508
|
-
"""
|
|
509
|
-
Copy attributes from object 'b' to object 'a', with options to include/exclude certain attributes.
|
|
498
|
+
"""Copy attributes from object 'b' to object 'a', with options to include/exclude certain attributes.
|
|
510
499
|
|
|
511
500
|
Args:
|
|
512
501
|
a (Any): Destination object to copy attributes to.
|
|
@@ -522,8 +511,7 @@ def copy_attr(a, b, include=(), exclude=()):
|
|
|
522
511
|
|
|
523
512
|
|
|
524
513
|
def intersect_dicts(da, db, exclude=()):
|
|
525
|
-
"""
|
|
526
|
-
Return a dictionary of intersecting keys with matching shapes, excluding 'exclude' keys, using da values.
|
|
514
|
+
"""Return a dictionary of intersecting keys with matching shapes, excluding 'exclude' keys, using da values.
|
|
527
515
|
|
|
528
516
|
Args:
|
|
529
517
|
da (dict): First dictionary.
|
|
@@ -537,8 +525,7 @@ def intersect_dicts(da, db, exclude=()):
|
|
|
537
525
|
|
|
538
526
|
|
|
539
527
|
def is_parallel(model):
|
|
540
|
-
"""
|
|
541
|
-
Return True if model is of type DP or DDP.
|
|
528
|
+
"""Return True if model is of type DP or DDP.
|
|
542
529
|
|
|
543
530
|
Args:
|
|
544
531
|
model (nn.Module): Model to check.
|
|
@@ -550,8 +537,7 @@ def is_parallel(model):
|
|
|
550
537
|
|
|
551
538
|
|
|
552
539
|
def unwrap_model(m: nn.Module) -> nn.Module:
|
|
553
|
-
"""
|
|
554
|
-
Unwrap compiled and parallel models to get the base model.
|
|
540
|
+
"""Unwrap compiled and parallel models to get the base model.
|
|
555
541
|
|
|
556
542
|
Args:
|
|
557
543
|
m (nn.Module): A model that may be wrapped by torch.compile (._orig_mod) or parallel wrappers such as
|
|
@@ -570,8 +556,7 @@ def unwrap_model(m: nn.Module) -> nn.Module:
|
|
|
570
556
|
|
|
571
557
|
|
|
572
558
|
def one_cycle(y1=0.0, y2=1.0, steps=100):
|
|
573
|
-
"""
|
|
574
|
-
Return a lambda function for sinusoidal ramp from y1 to y2 https://arxiv.org/pdf/1812.01187.pdf.
|
|
559
|
+
"""Return a lambda function for sinusoidal ramp from y1 to y2 https://arxiv.org/pdf/1812.01187.pdf.
|
|
575
560
|
|
|
576
561
|
Args:
|
|
577
562
|
y1 (float, optional): Initial value.
|
|
@@ -585,8 +570,7 @@ def one_cycle(y1=0.0, y2=1.0, steps=100):
|
|
|
585
570
|
|
|
586
571
|
|
|
587
572
|
def init_seeds(seed=0, deterministic=False):
|
|
588
|
-
"""
|
|
589
|
-
Initialize random number generator (RNG) seeds https://pytorch.org/docs/stable/notes/randomness.html.
|
|
573
|
+
"""Initialize random number generator (RNG) seeds https://pytorch.org/docs/stable/notes/randomness.html.
|
|
590
574
|
|
|
591
575
|
Args:
|
|
592
576
|
seed (int, optional): Random seed.
|
|
@@ -619,11 +603,10 @@ def unset_deterministic():
|
|
|
619
603
|
|
|
620
604
|
|
|
621
605
|
class ModelEMA:
|
|
622
|
-
"""
|
|
623
|
-
Updated Exponential Moving Average (EMA) implementation.
|
|
606
|
+
"""Updated Exponential Moving Average (EMA) implementation.
|
|
624
607
|
|
|
625
|
-
Keeps a moving average of everything in the model state_dict (parameters and buffers).
|
|
626
|
-
|
|
608
|
+
Keeps a moving average of everything in the model state_dict (parameters and buffers). For EMA details see
|
|
609
|
+
References.
|
|
627
610
|
|
|
628
611
|
To disable EMA set the `enabled` attribute to `False`.
|
|
629
612
|
|
|
@@ -639,8 +622,7 @@ class ModelEMA:
|
|
|
639
622
|
"""
|
|
640
623
|
|
|
641
624
|
def __init__(self, model, decay=0.9999, tau=2000, updates=0):
|
|
642
|
-
"""
|
|
643
|
-
Initialize EMA for 'model' with given arguments.
|
|
625
|
+
"""Initialize EMA for 'model' with given arguments.
|
|
644
626
|
|
|
645
627
|
Args:
|
|
646
628
|
model (nn.Module): Model to create EMA for.
|
|
@@ -656,8 +638,7 @@ class ModelEMA:
|
|
|
656
638
|
self.enabled = True
|
|
657
639
|
|
|
658
640
|
def update(self, model):
|
|
659
|
-
"""
|
|
660
|
-
Update EMA parameters.
|
|
641
|
+
"""Update EMA parameters.
|
|
661
642
|
|
|
662
643
|
Args:
|
|
663
644
|
model (nn.Module): Model to update EMA from.
|
|
@@ -674,8 +655,7 @@ class ModelEMA:
|
|
|
674
655
|
# assert v.dtype == msd[k].dtype == torch.float32, f'{k}: EMA {v.dtype}, model {msd[k].dtype}'
|
|
675
656
|
|
|
676
657
|
def update_attr(self, model, include=(), exclude=("process_group", "reducer")):
|
|
677
|
-
"""
|
|
678
|
-
Update attributes and save stripped model with optimizer removed.
|
|
658
|
+
"""Update attributes and save stripped model with optimizer removed.
|
|
679
659
|
|
|
680
660
|
Args:
|
|
681
661
|
model (nn.Module): Model to update attributes from.
|
|
@@ -687,8 +667,7 @@ class ModelEMA:
|
|
|
687
667
|
|
|
688
668
|
|
|
689
669
|
def strip_optimizer(f: str | Path = "best.pt", s: str = "", updates: dict[str, Any] | None = None) -> dict[str, Any]:
|
|
690
|
-
"""
|
|
691
|
-
Strip optimizer from 'f' to finalize training, optionally save as 's'.
|
|
670
|
+
"""Strip optimizer from 'f' to finalize training, optionally save as 's'.
|
|
692
671
|
|
|
693
672
|
Args:
|
|
694
673
|
f (str | Path): File path to model to strip the optimizer from.
|
|
@@ -748,8 +727,7 @@ def strip_optimizer(f: str | Path = "best.pt", s: str = "", updates: dict[str, A
|
|
|
748
727
|
|
|
749
728
|
|
|
750
729
|
def convert_optimizer_state_dict_to_fp16(state_dict):
|
|
751
|
-
"""
|
|
752
|
-
Convert the state_dict of a given optimizer to FP16, focusing on the 'state' key for tensor conversions.
|
|
730
|
+
"""Convert the state_dict of a given optimizer to FP16, focusing on the 'state' key for tensor conversions.
|
|
753
731
|
|
|
754
732
|
Args:
|
|
755
733
|
state_dict (dict): Optimizer state dictionary.
|
|
@@ -767,12 +745,11 @@ def convert_optimizer_state_dict_to_fp16(state_dict):
|
|
|
767
745
|
|
|
768
746
|
@contextmanager
|
|
769
747
|
def cuda_memory_usage(device=None):
|
|
770
|
-
"""
|
|
771
|
-
Monitor and manage CUDA memory usage.
|
|
748
|
+
"""Monitor and manage CUDA memory usage.
|
|
772
749
|
|
|
773
|
-
This function checks if CUDA is available and, if so, empties the CUDA cache to free up unused memory.
|
|
774
|
-
|
|
775
|
-
|
|
750
|
+
This function checks if CUDA is available and, if so, empties the CUDA cache to free up unused memory. It then
|
|
751
|
+
yields a dictionary containing memory usage information, which can be updated by the caller. Finally, it updates the
|
|
752
|
+
dictionary with the amount of memory reserved by CUDA on the specified device.
|
|
776
753
|
|
|
777
754
|
Args:
|
|
778
755
|
device (torch.device, optional): The CUDA device to query memory usage for.
|
|
@@ -792,8 +769,7 @@ def cuda_memory_usage(device=None):
|
|
|
792
769
|
|
|
793
770
|
|
|
794
771
|
def profile_ops(input, ops, n=10, device=None, max_num_obj=0):
|
|
795
|
-
"""
|
|
796
|
-
Ultralytics speed, memory and FLOPs profiler.
|
|
772
|
+
"""Ultralytics speed, memory and FLOPs profiler.
|
|
797
773
|
|
|
798
774
|
Args:
|
|
799
775
|
input (torch.Tensor | list): Input tensor(s) to profile.
|
|
@@ -878,8 +854,7 @@ def profile_ops(input, ops, n=10, device=None, max_num_obj=0):
|
|
|
878
854
|
|
|
879
855
|
|
|
880
856
|
class EarlyStopping:
|
|
881
|
-
"""
|
|
882
|
-
Early stopping class that stops training when a specified number of epochs have passed without improvement.
|
|
857
|
+
"""Early stopping class that stops training when a specified number of epochs have passed without improvement.
|
|
883
858
|
|
|
884
859
|
Attributes:
|
|
885
860
|
best_fitness (float): Best fitness value observed.
|
|
@@ -889,8 +864,7 @@ class EarlyStopping:
|
|
|
889
864
|
"""
|
|
890
865
|
|
|
891
866
|
def __init__(self, patience=50):
|
|
892
|
-
"""
|
|
893
|
-
Initialize early stopping object.
|
|
867
|
+
"""Initialize early stopping object.
|
|
894
868
|
|
|
895
869
|
Args:
|
|
896
870
|
patience (int, optional): Number of epochs to wait after fitness stops improving before stopping.
|
|
@@ -901,8 +875,7 @@ class EarlyStopping:
|
|
|
901
875
|
self.possible_stop = False # possible stop may occur next epoch
|
|
902
876
|
|
|
903
877
|
def __call__(self, epoch, fitness):
|
|
904
|
-
"""
|
|
905
|
-
Check whether to stop training.
|
|
878
|
+
"""Check whether to stop training.
|
|
906
879
|
|
|
907
880
|
Args:
|
|
908
881
|
epoch (int): Current epoch of training
|
|
@@ -939,8 +912,7 @@ def attempt_compile(
|
|
|
939
912
|
warmup: bool = False,
|
|
940
913
|
mode: bool | str = "default",
|
|
941
914
|
) -> torch.nn.Module:
|
|
942
|
-
"""
|
|
943
|
-
Compile a model with torch.compile and optionally warm up the graph to reduce first-iteration latency.
|
|
915
|
+
"""Compile a model with torch.compile and optionally warm up the graph to reduce first-iteration latency.
|
|
944
916
|
|
|
945
917
|
This utility attempts to compile the provided model using the inductor backend with dynamic shapes enabled and an
|
|
946
918
|
autotuning mode. If compilation is unavailable or fails, the original model is returned unchanged. An optional
|
|
@@ -958,15 +930,15 @@ def attempt_compile(
|
|
|
958
930
|
Returns:
|
|
959
931
|
model (torch.nn.Module): Compiled model if compilation succeeds, otherwise the original unmodified model.
|
|
960
932
|
|
|
961
|
-
Notes:
|
|
962
|
-
- If the current PyTorch build does not provide torch.compile, the function returns the input model immediately.
|
|
963
|
-
- Warmup runs under torch.inference_mode and may use torch.autocast for CUDA/MPS to align compute precision.
|
|
964
|
-
- CUDA devices are synchronized after warmup to account for asynchronous kernel execution.
|
|
965
|
-
|
|
966
933
|
Examples:
|
|
967
934
|
>>> device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
|
968
935
|
>>> # Try to compile and warm up a model with a 640x640 input
|
|
969
936
|
>>> model = attempt_compile(model, device=device, imgsz=640, use_autocast=True, warmup=True)
|
|
937
|
+
|
|
938
|
+
Notes:
|
|
939
|
+
- If the current PyTorch build does not provide torch.compile, the function returns the input model immediately.
|
|
940
|
+
- Warmup runs under torch.inference_mode and may use torch.autocast for CUDA/MPS to align compute precision.
|
|
941
|
+
- CUDA devices are synchronized after warmup to account for asynchronous kernel execution.
|
|
970
942
|
"""
|
|
971
943
|
if not hasattr(torch, "compile") or not mode:
|
|
972
944
|
return model
|
ultralytics/utils/tqdm.py
CHANGED
|
@@ -16,13 +16,12 @@ def is_noninteractive_console() -> bool:
|
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
class TQDM:
|
|
19
|
-
"""
|
|
20
|
-
Lightweight zero-dependency progress bar for Ultralytics.
|
|
19
|
+
"""Lightweight zero-dependency progress bar for Ultralytics.
|
|
21
20
|
|
|
22
|
-
Provides clean, rich-style progress bars suitable for various environments including Weights & Biases,
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
Provides clean, rich-style progress bars suitable for various environments including Weights & Biases, console
|
|
22
|
+
outputs, and other logging systems. Features zero external dependencies, clean single-line output, rich-style
|
|
23
|
+
progress bars with Unicode block characters, context manager support, iterator protocol support, and dynamic
|
|
24
|
+
description updates.
|
|
26
25
|
|
|
27
26
|
Attributes:
|
|
28
27
|
iterable (object): Iterable to wrap with progress bar.
|
|
@@ -94,8 +93,7 @@ class TQDM:
|
|
|
94
93
|
initial: int = 0,
|
|
95
94
|
**kwargs,
|
|
96
95
|
) -> None:
|
|
97
|
-
"""
|
|
98
|
-
Initialize the TQDM progress bar with specified configuration options.
|
|
96
|
+
"""Initialize the TQDM progress bar with specified configuration options.
|
|
99
97
|
|
|
100
98
|
Args:
|
|
101
99
|
iterable (object, optional): Iterable to wrap with progress bar.
|
ultralytics/utils/triton.py
CHANGED
|
@@ -8,11 +8,10 @@ import numpy as np
|
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
class TritonRemoteModel:
|
|
11
|
-
"""
|
|
12
|
-
Client for interacting with a remote Triton Inference Server model.
|
|
11
|
+
"""Client for interacting with a remote Triton Inference Server model.
|
|
13
12
|
|
|
14
|
-
This class provides a convenient interface for sending inference requests to a Triton Inference Server
|
|
15
|
-
|
|
13
|
+
This class provides a convenient interface for sending inference requests to a Triton Inference Server and
|
|
14
|
+
processing the responses. Supports both HTTP and gRPC communication protocols.
|
|
16
15
|
|
|
17
16
|
Attributes:
|
|
18
17
|
endpoint (str): The name of the model on the Triton server.
|
|
@@ -38,8 +37,7 @@ class TritonRemoteModel:
|
|
|
38
37
|
"""
|
|
39
38
|
|
|
40
39
|
def __init__(self, url: str, endpoint: str = "", scheme: str = ""):
|
|
41
|
-
"""
|
|
42
|
-
Initialize the TritonRemoteModel for interacting with a remote Triton Inference Server.
|
|
40
|
+
"""Initialize the TritonRemoteModel for interacting with a remote Triton Inference Server.
|
|
43
41
|
|
|
44
42
|
Arguments may be provided individually or parsed from a collective 'url' argument of the form
|
|
45
43
|
<scheme>://<netloc>/<endpoint>/<task_name>
|
|
@@ -88,16 +86,15 @@ class TritonRemoteModel:
|
|
|
88
86
|
self.metadata = eval(config.get("parameters", {}).get("metadata", {}).get("string_value", "None"))
|
|
89
87
|
|
|
90
88
|
def __call__(self, *inputs: np.ndarray) -> list[np.ndarray]:
|
|
91
|
-
"""
|
|
92
|
-
Call the model with the given inputs and return inference results.
|
|
89
|
+
"""Call the model with the given inputs and return inference results.
|
|
93
90
|
|
|
94
91
|
Args:
|
|
95
|
-
*inputs (np.ndarray): Input data to the model. Each array should match the expected shape and type
|
|
96
|
-
|
|
92
|
+
*inputs (np.ndarray): Input data to the model. Each array should match the expected shape and type for the
|
|
93
|
+
corresponding model input.
|
|
97
94
|
|
|
98
95
|
Returns:
|
|
99
|
-
(list[np.ndarray]): Model outputs with the same dtype as the input. Each element in the list
|
|
100
|
-
|
|
96
|
+
(list[np.ndarray]): Model outputs with the same dtype as the input. Each element in the list corresponds to
|
|
97
|
+
one of the model's output tensors.
|
|
101
98
|
|
|
102
99
|
Examples:
|
|
103
100
|
>>> model = TritonRemoteModel(url="localhost:8000", endpoint="yolov8", scheme="http")
|