dgenerate-ultralytics-headless 8.3.248__py3-none-any.whl → 8.4.7__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.
Files changed (97) hide show
  1. {dgenerate_ultralytics_headless-8.3.248.dist-info → dgenerate_ultralytics_headless-8.4.7.dist-info}/METADATA +52 -61
  2. {dgenerate_ultralytics_headless-8.3.248.dist-info → dgenerate_ultralytics_headless-8.4.7.dist-info}/RECORD +97 -84
  3. {dgenerate_ultralytics_headless-8.3.248.dist-info → dgenerate_ultralytics_headless-8.4.7.dist-info}/WHEEL +1 -1
  4. tests/__init__.py +2 -2
  5. tests/conftest.py +1 -1
  6. tests/test_cuda.py +8 -2
  7. tests/test_engine.py +8 -8
  8. tests/test_exports.py +11 -4
  9. tests/test_integrations.py +9 -9
  10. tests/test_python.py +41 -16
  11. tests/test_solutions.py +3 -3
  12. ultralytics/__init__.py +1 -1
  13. ultralytics/cfg/__init__.py +31 -31
  14. ultralytics/cfg/datasets/TT100K.yaml +346 -0
  15. ultralytics/cfg/datasets/coco12-formats.yaml +101 -0
  16. ultralytics/cfg/default.yaml +3 -1
  17. ultralytics/cfg/models/26/yolo26-cls.yaml +33 -0
  18. ultralytics/cfg/models/26/yolo26-obb.yaml +52 -0
  19. ultralytics/cfg/models/26/yolo26-p2.yaml +60 -0
  20. ultralytics/cfg/models/26/yolo26-p6.yaml +62 -0
  21. ultralytics/cfg/models/26/yolo26-pose.yaml +53 -0
  22. ultralytics/cfg/models/26/yolo26-seg.yaml +52 -0
  23. ultralytics/cfg/models/26/yolo26.yaml +52 -0
  24. ultralytics/cfg/models/26/yoloe-26-seg.yaml +53 -0
  25. ultralytics/cfg/models/26/yoloe-26.yaml +53 -0
  26. ultralytics/data/annotator.py +2 -2
  27. ultralytics/data/augment.py +15 -0
  28. ultralytics/data/converter.py +76 -45
  29. ultralytics/data/dataset.py +1 -1
  30. ultralytics/data/utils.py +2 -2
  31. ultralytics/engine/exporter.py +34 -28
  32. ultralytics/engine/model.py +38 -37
  33. ultralytics/engine/predictor.py +17 -17
  34. ultralytics/engine/results.py +22 -15
  35. ultralytics/engine/trainer.py +83 -48
  36. ultralytics/engine/tuner.py +20 -11
  37. ultralytics/engine/validator.py +16 -16
  38. ultralytics/models/fastsam/predict.py +1 -1
  39. ultralytics/models/yolo/classify/predict.py +1 -1
  40. ultralytics/models/yolo/classify/train.py +1 -1
  41. ultralytics/models/yolo/classify/val.py +1 -1
  42. ultralytics/models/yolo/detect/predict.py +2 -2
  43. ultralytics/models/yolo/detect/train.py +6 -3
  44. ultralytics/models/yolo/detect/val.py +7 -1
  45. ultralytics/models/yolo/model.py +8 -8
  46. ultralytics/models/yolo/obb/predict.py +2 -2
  47. ultralytics/models/yolo/obb/train.py +3 -3
  48. ultralytics/models/yolo/obb/val.py +1 -1
  49. ultralytics/models/yolo/pose/predict.py +1 -1
  50. ultralytics/models/yolo/pose/train.py +3 -1
  51. ultralytics/models/yolo/pose/val.py +1 -1
  52. ultralytics/models/yolo/segment/predict.py +3 -3
  53. ultralytics/models/yolo/segment/train.py +4 -4
  54. ultralytics/models/yolo/segment/val.py +2 -2
  55. ultralytics/models/yolo/yoloe/train.py +6 -1
  56. ultralytics/models/yolo/yoloe/train_seg.py +6 -1
  57. ultralytics/nn/autobackend.py +14 -8
  58. ultralytics/nn/modules/__init__.py +8 -0
  59. ultralytics/nn/modules/block.py +128 -8
  60. ultralytics/nn/modules/head.py +788 -203
  61. ultralytics/nn/tasks.py +86 -41
  62. ultralytics/nn/text_model.py +5 -2
  63. ultralytics/optim/__init__.py +5 -0
  64. ultralytics/optim/muon.py +338 -0
  65. ultralytics/solutions/ai_gym.py +3 -3
  66. ultralytics/solutions/config.py +1 -1
  67. ultralytics/solutions/heatmap.py +1 -1
  68. ultralytics/solutions/instance_segmentation.py +2 -2
  69. ultralytics/solutions/object_counter.py +1 -1
  70. ultralytics/solutions/parking_management.py +1 -1
  71. ultralytics/solutions/solutions.py +2 -2
  72. ultralytics/trackers/byte_tracker.py +7 -7
  73. ultralytics/trackers/track.py +1 -1
  74. ultralytics/utils/__init__.py +8 -8
  75. ultralytics/utils/benchmarks.py +26 -26
  76. ultralytics/utils/callbacks/platform.py +173 -64
  77. ultralytics/utils/callbacks/tensorboard.py +2 -0
  78. ultralytics/utils/callbacks/wb.py +6 -1
  79. ultralytics/utils/checks.py +28 -9
  80. ultralytics/utils/dist.py +1 -0
  81. ultralytics/utils/downloads.py +5 -3
  82. ultralytics/utils/export/engine.py +19 -10
  83. ultralytics/utils/export/imx.py +38 -20
  84. ultralytics/utils/export/tensorflow.py +21 -21
  85. ultralytics/utils/files.py +2 -2
  86. ultralytics/utils/loss.py +597 -203
  87. ultralytics/utils/metrics.py +2 -1
  88. ultralytics/utils/ops.py +11 -2
  89. ultralytics/utils/patches.py +42 -0
  90. ultralytics/utils/plotting.py +3 -0
  91. ultralytics/utils/tal.py +100 -20
  92. ultralytics/utils/torch_utils.py +1 -1
  93. ultralytics/utils/tqdm.py +4 -1
  94. ultralytics/utils/tuner.py +2 -5
  95. {dgenerate_ultralytics_headless-8.3.248.dist-info → dgenerate_ultralytics_headless-8.4.7.dist-info}/entry_points.txt +0 -0
  96. {dgenerate_ultralytics_headless-8.3.248.dist-info → dgenerate_ultralytics_headless-8.4.7.dist-info}/licenses/LICENSE +0 -0
  97. {dgenerate_ultralytics_headless-8.3.248.dist-info → dgenerate_ultralytics_headless-8.4.7.dist-info}/top_level.txt +0 -0
@@ -21,27 +21,39 @@ from ultralytics.utils.torch_utils import copy_attr
21
21
  MCT_CONFIG = {
22
22
  "YOLO11": {
23
23
  "detect": {
24
- "layer_names": ["sub", "mul_2", "add_14", "cat_21"],
24
+ "layer_names": ["sub", "mul_2", "add_14", "cat_19"],
25
25
  "weights_memory": 2585350.2439,
26
- "n_layers": 238,
26
+ "n_layers": {238, 239},
27
27
  },
28
28
  "pose": {
29
- "layer_names": ["sub", "mul_2", "add_14", "cat_22", "cat_23", "mul_4", "add_15"],
29
+ "layer_names": ["sub", "mul_2", "add_14", "cat_21", "cat_22", "mul_4", "add_15"],
30
30
  "weights_memory": 2437771.67,
31
- "n_layers": 257,
31
+ "n_layers": {257, 258},
32
+ },
33
+ "classify": {"layer_names": [], "weights_memory": np.inf, "n_layers": {112}},
34
+ "segment": {
35
+ "layer_names": ["sub", "mul_2", "add_14", "cat_21"],
36
+ "weights_memory": 2466604.8,
37
+ "n_layers": {265, 266},
32
38
  },
33
- "classify": {"layer_names": [], "weights_memory": np.inf, "n_layers": 112},
34
- "segment": {"layer_names": ["sub", "mul_2", "add_14", "cat_22"], "weights_memory": 2466604.8, "n_layers": 265},
35
39
  },
36
40
  "YOLOv8": {
37
- "detect": {"layer_names": ["sub", "mul", "add_6", "cat_17"], "weights_memory": 2550540.8, "n_layers": 168},
41
+ "detect": {
42
+ "layer_names": ["sub", "mul", "add_6", "cat_15"],
43
+ "weights_memory": 2550540.8,
44
+ "n_layers": {168, 169},
45
+ },
38
46
  "pose": {
39
- "layer_names": ["add_7", "mul_2", "cat_19", "mul", "sub", "add_6", "cat_18"],
47
+ "layer_names": ["add_7", "mul_2", "cat_17", "mul", "sub", "add_6", "cat_18"],
40
48
  "weights_memory": 2482451.85,
41
- "n_layers": 187,
49
+ "n_layers": {187, 188},
50
+ },
51
+ "classify": {"layer_names": [], "weights_memory": np.inf, "n_layers": {73}},
52
+ "segment": {
53
+ "layer_names": ["sub", "mul", "add_6", "cat_17"],
54
+ "weights_memory": 2580060.0,
55
+ "n_layers": {195, 196},
42
56
  },
43
- "classify": {"layer_names": [], "weights_memory": np.inf, "n_layers": 73},
44
- "segment": {"layer_names": ["sub", "mul", "add_6", "cat_18"], "weights_memory": 2580060.0, "n_layers": 195},
45
57
  },
46
58
  }
47
59
 
@@ -104,20 +116,26 @@ class FXModel(torch.nn.Module):
104
116
  return x
105
117
 
106
118
 
107
- def _inference(self, x: list[torch.Tensor]) -> tuple[torch.Tensor]:
119
+ def _inference(self, x: dict[str, torch.Tensor]) -> tuple[torch.Tensor]:
108
120
  """Decode boxes and cls scores for imx object detection."""
109
- x_cat = torch.cat([xi.view(x[0].shape[0], self.no, -1) for xi in x], 2)
110
- box, cls = x_cat.split((self.reg_max * 4, self.nc), 1)
111
- dbox = self.decode_bboxes(self.dfl(box), self.anchors.unsqueeze(0)) * self.strides
112
- return dbox.transpose(1, 2), cls.sigmoid().permute(0, 2, 1)
121
+ dbox = self.decode_bboxes(self.dfl(x["boxes"]), self.anchors.unsqueeze(0)) * self.strides
122
+ return dbox.transpose(1, 2), x["scores"].sigmoid().permute(0, 2, 1)
113
123
 
114
124
 
115
125
  def pose_forward(self, x: list[torch.Tensor]) -> tuple[torch.Tensor, torch.Tensor, torch.Tensor]:
116
126
  """Forward pass for imx pose estimation, including keypoint decoding."""
117
127
  bs = x[0].shape[0] # batch size
118
- kpt = torch.cat([self.cv4[i](x[i]).view(bs, self.nk, -1) for i in range(self.nl)], -1) # (bs, 17*3, h*w)
128
+ nk_out = getattr(self, "nk_output", self.nk)
129
+ kpt = torch.cat([self.cv4[i](x[i]).view(bs, nk_out, -1) for i in range(self.nl)], -1)
130
+
131
+ # If using Pose26 with 5 dims, convert to 3 dims for export
132
+ if hasattr(self, "nk_output") and self.nk_output != self.nk:
133
+ spatial = kpt.shape[-1]
134
+ kpt = kpt.view(bs, self.kpt_shape[0], self.kpt_shape[1] + 2, spatial)
135
+ kpt = kpt[:, :, :-2, :] # Remove sigma_x, sigma_y
136
+ kpt = kpt.view(bs, self.nk, spatial)
119
137
  x = Detect.forward(self, x)
120
- pred_kpt = self.kpts_decode(bs, kpt)
138
+ pred_kpt = self.kpts_decode(kpt)
121
139
  return *x, pred_kpt.permute(0, 2, 1)
122
140
 
123
141
 
@@ -219,7 +237,7 @@ def torch2imx(
219
237
  Examples:
220
238
  >>> from ultralytics import YOLO
221
239
  >>> model = YOLO("yolo11n.pt")
222
- >>> path, _ = export_imx(model, "model.imx", conf=0.25, iou=0.45, max_det=300)
240
+ >>> path, _ = export_imx(model, "model.imx", conf=0.25, iou=0.7, max_det=300)
223
241
 
224
242
  Notes:
225
243
  - Requires model_compression_toolkit, onnx, edgemdt_tpc, and edge-mdt-cl packages
@@ -245,7 +263,7 @@ def torch2imx(
245
263
  mct_config = MCT_CONFIG["YOLO11" if "C2PSA" in model.__str__() else "YOLOv8"][model.task]
246
264
 
247
265
  # Check if the model has the expected number of layers
248
- if len(list(model.modules())) != mct_config["n_layers"]:
266
+ if len(list(model.modules())) not in mct_config["n_layers"]:
249
267
  raise ValueError("IMX export only supported for YOLOv8n and YOLO11n models.")
250
268
 
251
269
  for layer_name in mct_config["layer_names"]:
@@ -2,12 +2,13 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
+ from functools import partial
5
6
  from pathlib import Path
6
7
 
7
8
  import numpy as np
8
9
  import torch
9
10
 
10
- from ultralytics.nn.modules import Detect, Pose
11
+ from ultralytics.nn.modules import Detect, Pose, Pose26
11
12
  from ultralytics.utils import LOGGER
12
13
  from ultralytics.utils.downloads import attempt_download_asset
13
14
  from ultralytics.utils.files import spaces_in_path
@@ -15,43 +16,42 @@ from ultralytics.utils.tal import make_anchors
15
16
 
16
17
 
17
18
  def tf_wrapper(model: torch.nn.Module) -> torch.nn.Module:
18
- """A wrapper to add TensorFlow compatible inference methods to Detect and Pose layers."""
19
+ """A wrapper for TensorFlow export compatibility (TF-specific handling is now in head modules)."""
19
20
  for m in model.modules():
20
21
  if not isinstance(m, Detect):
21
22
  continue
22
23
  import types
23
24
 
24
- m._inference = types.MethodType(_tf_inference, m)
25
- if type(m) is Pose:
26
- m.kpts_decode = types.MethodType(tf_kpts_decode, m)
25
+ m._get_decode_boxes = types.MethodType(_tf_decode_boxes, m)
26
+ if isinstance(m, Pose):
27
+ m.kpts_decode = types.MethodType(partial(_tf_kpts_decode, is_pose26=type(m) is Pose26), m)
27
28
  return model
28
29
 
29
30
 
30
- def _tf_inference(self, x: list[torch.Tensor]) -> tuple[torch.Tensor]:
31
- """Decode boxes and cls scores for tf object detection."""
32
- shape = x[0].shape # BCHW
33
- x_cat = torch.cat([xi.view(x[0].shape[0], self.no, -1) for xi in x], 2)
34
- box, cls = x_cat.split((self.reg_max * 4, self.nc), 1)
35
- if self.dynamic or self.shape != shape:
36
- self.anchors, self.strides = (x.transpose(0, 1) for x in make_anchors(x, self.stride, 0.5))
31
+ def _tf_decode_boxes(self, x: dict[str, torch.Tensor]) -> torch.Tensor:
32
+ """Decode bounding boxes for TensorFlow export."""
33
+ shape = x["feats"][0].shape # BCHW
34
+ boxes = x["boxes"]
35
+ if self.format != "imx" and (self.dynamic or self.shape != shape):
36
+ self.anchors, self.strides = (a.transpose(0, 1) for a in make_anchors(x["feats"], self.stride, 0.5))
37
37
  self.shape = shape
38
- grid_h, grid_w = shape[2], shape[3]
39
- grid_size = torch.tensor([grid_w, grid_h, grid_w, grid_h], device=box.device).reshape(1, 4, 1)
38
+ grid_h, grid_w = shape[2:4]
39
+ grid_size = torch.tensor([grid_w, grid_h, grid_w, grid_h], device=boxes.device).reshape(1, 4, 1)
40
40
  norm = self.strides / (self.stride[0] * grid_size)
41
- dbox = self.decode_bboxes(self.dfl(box) * norm, self.anchors.unsqueeze(0) * norm[:, :2])
42
- return torch.cat((dbox, cls.sigmoid()), 1)
41
+ dbox = self.decode_bboxes(self.dfl(boxes) * norm, self.anchors.unsqueeze(0) * norm[:, :2])
42
+ return dbox
43
43
 
44
44
 
45
- def tf_kpts_decode(self, bs: int, kpts: torch.Tensor) -> torch.Tensor:
46
- """Decode keypoints for tf pose estimation."""
45
+ def _tf_kpts_decode(self, kpts: torch.Tensor, is_pose26: bool = False) -> torch.Tensor:
46
+ """Decode keypoints for TensorFlow export."""
47
47
  ndim = self.kpt_shape[1]
48
- # required for TFLite export to avoid 'PLACEHOLDER_FOR_GREATER_OP_CODES' bug
48
+ bs = kpts.shape[0]
49
49
  # Precompute normalization factor to increase numerical stability
50
50
  y = kpts.view(bs, *self.kpt_shape, -1)
51
- grid_h, grid_w = self.shape[2], self.shape[3]
51
+ grid_h, grid_w = self.shape[2:4]
52
52
  grid_size = torch.tensor([grid_w, grid_h], device=y.device).reshape(1, 2, 1)
53
53
  norm = self.strides / (self.stride[0] * grid_size)
54
- a = (y[:, :, :2] * 2.0 + (self.anchors - 0.5)) * norm
54
+ a = ((y[:, :, :2] + self.anchors) if is_pose26 else (y[:, :, :2] * 2.0 + (self.anchors - 0.5))) * norm
55
55
  if ndim == 3:
56
56
  a = torch.cat((a, y[:, :, 2:3].sigmoid()), 2)
57
57
  return a.view(bs, self.nk, -1)
@@ -180,7 +180,7 @@ def get_latest_run(search_dir: str = ".") -> str:
180
180
  return max(last_list, key=os.path.getctime) if last_list else ""
181
181
 
182
182
 
183
- def update_models(model_names: tuple = ("yolo11n.pt",), source_dir: Path = Path("."), update_names: bool = False):
183
+ def update_models(model_names: tuple = ("yolo26n.pt",), source_dir: Path = Path("."), update_names: bool = False):
184
184
  """Update and re-save specified YOLO models in an 'updated_models' subdirectory.
185
185
 
186
186
  Args:
@@ -191,7 +191,7 @@ def update_models(model_names: tuple = ("yolo11n.pt",), source_dir: Path = Path(
191
191
  Examples:
192
192
  Update specified YOLO models and save them in 'updated_models' subdirectory:
193
193
  >>> from ultralytics.utils.files import update_models
194
- >>> model_names = ("yolo11n.pt", "yolov8s.pt")
194
+ >>> model_names = ("yolo26n.pt", "yolo11s.pt")
195
195
  >>> update_models(model_names, source_dir=Path("/models"), update_names=True)
196
196
  """
197
197
  from ultralytics import YOLO