ultralytics 8.1.42__py3-none-any.whl → 8.1.44__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.

Potentially problematic release.


This version of ultralytics might be problematic. Click here for more details.

Files changed (58) hide show
  1. ultralytics/__init__.py +3 -2
  2. ultralytics/cfg/models/v9/yolov9c-seg.yaml +1 -1
  3. ultralytics/cfg/models/v9/yolov9c.yaml +1 -1
  4. ultralytics/cfg/models/v9/yolov9e-seg.yaml +2 -3
  5. ultralytics/cfg/models/v9/yolov9e.yaml +2 -3
  6. ultralytics/data/__init__.py +3 -8
  7. ultralytics/data/augment.py +14 -11
  8. ultralytics/data/base.py +1 -1
  9. ultralytics/data/build.py +1 -1
  10. ultralytics/data/converter.py +4 -3
  11. ultralytics/data/dataset.py +149 -144
  12. ultralytics/data/explorer/explorer.py +10 -11
  13. ultralytics/data/explorer/gui/dash.py +3 -3
  14. ultralytics/data/explorer/utils.py +3 -2
  15. ultralytics/data/loaders.py +3 -3
  16. ultralytics/data/utils.py +1 -1
  17. ultralytics/engine/exporter.py +3 -2
  18. ultralytics/engine/model.py +2 -1
  19. ultralytics/engine/trainer.py +2 -1
  20. ultralytics/hub/auth.py +3 -3
  21. ultralytics/hub/session.py +3 -3
  22. ultralytics/hub/utils.py +6 -6
  23. ultralytics/models/fastsam/prompt.py +4 -1
  24. ultralytics/models/rtdetr/val.py +1 -1
  25. ultralytics/models/sam/modules/tiny_encoder.py +2 -2
  26. ultralytics/models/sam/modules/transformer.py +1 -1
  27. ultralytics/models/sam/predict.py +16 -13
  28. ultralytics/models/yolo/classify/train.py +2 -1
  29. ultralytics/models/yolo/detect/val.py +1 -1
  30. ultralytics/models/yolo/model.py +1 -1
  31. ultralytics/models/yolo/obb/val.py +1 -1
  32. ultralytics/models/yolo/world/train_world.py +2 -2
  33. ultralytics/nn/modules/__init__.py +8 -8
  34. ultralytics/nn/modules/head.py +1 -1
  35. ultralytics/nn/tasks.py +7 -7
  36. ultralytics/solutions/heatmap.py +14 -27
  37. ultralytics/solutions/object_counter.py +12 -22
  38. ultralytics/trackers/byte_tracker.py +1 -1
  39. ultralytics/trackers/utils/kalman_filter.py +4 -4
  40. ultralytics/trackers/utils/matching.py +1 -1
  41. ultralytics/utils/__init__.py +56 -41
  42. ultralytics/utils/benchmarks.py +1 -2
  43. ultralytics/utils/callbacks/clearml.py +4 -3
  44. ultralytics/utils/callbacks/hub.py +1 -4
  45. ultralytics/utils/callbacks/mlflow.py +1 -1
  46. ultralytics/utils/callbacks/tensorboard.py +1 -0
  47. ultralytics/utils/callbacks/wb.py +5 -5
  48. ultralytics/utils/checks.py +17 -20
  49. ultralytics/utils/metrics.py +3 -3
  50. ultralytics/utils/ops.py +1 -1
  51. ultralytics/utils/plotting.py +67 -40
  52. ultralytics/utils/torch_utils.py +13 -6
  53. {ultralytics-8.1.42.dist-info → ultralytics-8.1.44.dist-info}/METADATA +1 -1
  54. {ultralytics-8.1.42.dist-info → ultralytics-8.1.44.dist-info}/RECORD +58 -58
  55. {ultralytics-8.1.42.dist-info → ultralytics-8.1.44.dist-info}/LICENSE +0 -0
  56. {ultralytics-8.1.42.dist-info → ultralytics-8.1.44.dist-info}/WHEEL +0 -0
  57. {ultralytics-8.1.42.dist-info → ultralytics-8.1.44.dist-info}/entry_points.txt +0 -0
  58. {ultralytics-8.1.42.dist-info → ultralytics-8.1.44.dist-info}/top_level.txt +0 -0
@@ -5,7 +5,6 @@ from typing import List
5
5
 
6
6
  import cv2
7
7
  import numpy as np
8
- import pandas as pd
9
8
 
10
9
  from ultralytics.data.augment import LetterBox
11
10
  from ultralytics.utils import LOGGER as logger
@@ -64,8 +63,10 @@ def plot_query_result(similar_set, plot_labels=True):
64
63
  similar_set (list): Pyarrow or pandas object containing the similar data points
65
64
  plot_labels (bool): Whether to plot labels or not
66
65
  """
66
+ import pandas # scope for faster 'import ultralytics'
67
+
67
68
  similar_set = (
68
- similar_set.to_dict(orient="list") if isinstance(similar_set, pd.DataFrame) else similar_set.to_pydict()
69
+ similar_set.to_dict(orient="list") if isinstance(similar_set, pandas.DataFrame) else similar_set.to_pydict()
69
70
  )
70
71
  empty_masks = [[[]]]
71
72
  empty_boxes = [[]]
@@ -15,8 +15,8 @@ import requests
15
15
  import torch
16
16
  from PIL import Image
17
17
 
18
- from ultralytics.data.utils import IMG_FORMATS, VID_FORMATS, FORMATS_HELP_MSG
19
- from ultralytics.utils import LOGGER, is_colab, is_kaggle, ops
18
+ from ultralytics.data.utils import FORMATS_HELP_MSG, IMG_FORMATS, VID_FORMATS
19
+ from ultralytics.utils import IS_COLAB, IS_KAGGLE, LOGGER, ops
20
20
  from ultralytics.utils.checks import check_requirements
21
21
 
22
22
 
@@ -87,7 +87,7 @@ class LoadStreams:
87
87
  # YouTube format i.e. 'https://www.youtube.com/watch?v=Zgi9g1ksQHc' or 'https://youtu.be/LNwODJXcvt4'
88
88
  s = get_best_youtube_url(s)
89
89
  s = eval(s) if s.isnumeric() else s # i.e. s = '0' local webcam
90
- if s == 0 and (is_colab() or is_kaggle()):
90
+ if s == 0 and (IS_COLAB or IS_KAGGLE):
91
91
  raise NotImplementedError(
92
92
  "'source=0' webcam not supported in Colab and Kaggle notebooks. "
93
93
  "Try running 'source=0' in a local environment."
ultralytics/data/utils.py CHANGED
@@ -27,9 +27,9 @@ from ultralytics.utils import (
27
27
  clean_url,
28
28
  colorstr,
29
29
  emojis,
30
+ is_dir_writeable,
30
31
  yaml_load,
31
32
  yaml_save,
32
- is_dir_writeable,
33
33
  )
34
34
  from ultralytics.utils.checks import check_file, check_font, is_ascii
35
35
  from ultralytics.utils.downloads import download, safe_download, unzip_file
@@ -75,6 +75,7 @@ from ultralytics.utils import (
75
75
  LINUX,
76
76
  LOGGER,
77
77
  MACOS,
78
+ PYTHON_VERSION,
78
79
  ROOT,
79
80
  WINDOWS,
80
81
  __version__,
@@ -83,7 +84,7 @@ from ultralytics.utils import (
83
84
  get_default_args,
84
85
  yaml_save,
85
86
  )
86
- from ultralytics.utils.checks import PYTHON_VERSION, check_imgsz, check_is_path_safe, check_requirements, check_version
87
+ from ultralytics.utils.checks import check_imgsz, check_is_path_safe, check_requirements, check_version
87
88
  from ultralytics.utils.downloads import attempt_download_asset, get_github_assets
88
89
  from ultralytics.utils.files import file_size, spaces_in_path
89
90
  from ultralytics.utils.ops import Profile
@@ -92,7 +93,7 @@ from ultralytics.utils.torch_utils import TORCH_1_13, get_latest_opset, select_d
92
93
 
93
94
  def export_formats():
94
95
  """YOLOv8 export formats."""
95
- import pandas
96
+ import pandas # scope for faster 'import ultralytics'
96
97
 
97
98
  x = [
98
99
  ["PyTorch", "-", ".pt", True, True],
@@ -321,9 +321,10 @@ class Model(nn.Module):
321
321
  AssertionError: If the model is not a PyTorch model.
322
322
  """
323
323
  self._check_is_pytorch_model()
324
- from ultralytics import __version__
325
324
  from datetime import datetime
326
325
 
326
+ from ultralytics import __version__
327
+
327
328
  updates = {
328
329
  "date": datetime.now().isoformat(),
329
330
  "version": __version__,
@@ -464,7 +464,8 @@ class BaseTrainer:
464
464
  def save_model(self):
465
465
  """Save model training checkpoints with additional metadata."""
466
466
  import io
467
- import pandas as pd # scope for faster startup
467
+
468
+ import pandas as pd # scope for faster 'import ultralytics'
468
469
 
469
470
  # Serialize ckpt to a byte buffer once (faster than repeated torch.save() calls)
470
471
  buffer = io.BytesIO()
ultralytics/hub/auth.py CHANGED
@@ -3,7 +3,7 @@
3
3
  import requests
4
4
 
5
5
  from ultralytics.hub.utils import HUB_API_ROOT, HUB_WEB_ROOT, PREFIX, request_with_credentials
6
- from ultralytics.utils import LOGGER, SETTINGS, emojis, is_colab
6
+ from ultralytics.utils import IS_COLAB, LOGGER, SETTINGS, emojis
7
7
 
8
8
  API_KEY_URL = f"{HUB_WEB_ROOT}/settings?tab=api+keys"
9
9
 
@@ -50,7 +50,7 @@ class Auth:
50
50
  # Attempt to authenticate with the provided API key
51
51
  success = self.authenticate()
52
52
  # If the API key is not provided and the environment is a Google Colab notebook
53
- elif is_colab():
53
+ elif IS_COLAB:
54
54
  # Attempt to authenticate using browser cookies
55
55
  success = self.auth_with_cookies()
56
56
  else:
@@ -109,7 +109,7 @@ class Auth:
109
109
  Returns:
110
110
  (bool): True if authentication is successful, False otherwise.
111
111
  """
112
- if not is_colab():
112
+ if not IS_COLAB:
113
113
  return False # Currently only works with Colab
114
114
  try:
115
115
  authn = request_with_credentials(f"{HUB_API_ROOT}/v1/auth/auto")
@@ -7,11 +7,11 @@ from pathlib import Path
7
7
 
8
8
  import requests
9
9
 
10
- from ultralytics.hub.utils import HUB_WEB_ROOT, HELP_MSG, PREFIX, TQDM
11
- from ultralytics.utils import LOGGER, SETTINGS, __version__, checks, emojis, is_colab
10
+ from ultralytics.hub.utils import HELP_MSG, HUB_WEB_ROOT, PREFIX, TQDM
11
+ from ultralytics.utils import IS_COLAB, LOGGER, SETTINGS, __version__, checks, emojis
12
12
  from ultralytics.utils.errors import HUBModelError
13
13
 
14
- AGENT_NAME = f"python-{__version__}-colab" if is_colab() else f"python-{__version__}-local"
14
+ AGENT_NAME = f"python-{__version__}-colab" if IS_COLAB else f"python-{__version__}-local"
15
15
 
16
16
 
17
17
  class HUBTrainingSession:
ultralytics/hub/utils.py CHANGED
@@ -12,6 +12,9 @@ import requests
12
12
  from ultralytics.utils import (
13
13
  ARGV,
14
14
  ENVIRONMENT,
15
+ IS_COLAB,
16
+ IS_GIT_DIR,
17
+ IS_PIP_PACKAGE,
15
18
  LOGGER,
16
19
  ONLINE,
17
20
  RANK,
@@ -22,9 +25,6 @@ from ultralytics.utils import (
22
25
  __version__,
23
26
  colorstr,
24
27
  get_git_origin_url,
25
- is_colab,
26
- is_git_dir,
27
- is_pip_package,
28
28
  )
29
29
  from ultralytics.utils.downloads import GITHUB_ASSETS_NAMES
30
30
 
@@ -48,7 +48,7 @@ def request_with_credentials(url: str) -> any:
48
48
  Raises:
49
49
  OSError: If the function is not run in a Google Colab environment.
50
50
  """
51
- if not is_colab():
51
+ if not IS_COLAB:
52
52
  raise OSError("request_with_credentials() must run in a Colab environment")
53
53
  from google.colab import output # noqa
54
54
  from IPython import display # noqa
@@ -189,7 +189,7 @@ class Events:
189
189
  self.t = 0.0 # rate limit timer (seconds)
190
190
  self.metadata = {
191
191
  "cli": Path(ARGV[0]).name == "yolo",
192
- "install": "git" if is_git_dir() else "pip" if is_pip_package() else "other",
192
+ "install": "git" if IS_GIT_DIR else "pip" if IS_PIP_PACKAGE else "other",
193
193
  "python": ".".join(platform.python_version_tuple()[:2]), # i.e. 3.10
194
194
  "version": __version__,
195
195
  "env": ENVIRONMENT,
@@ -201,7 +201,7 @@ class Events:
201
201
  and RANK in {-1, 0}
202
202
  and not TESTS_RUNNING
203
203
  and ONLINE
204
- and (is_pip_package() or get_git_origin_url() == "https://github.com/ultralytics/ultralytics.git")
204
+ and (IS_PIP_PACKAGE or get_git_origin_url() == "https://github.com/ultralytics/ultralytics.git")
205
205
  )
206
206
 
207
207
  def __call__(self, cfg):
@@ -4,7 +4,6 @@ import os
4
4
  from pathlib import Path
5
5
 
6
6
  import cv2
7
- import matplotlib.pyplot as plt
8
7
  import numpy as np
9
8
  import torch
10
9
  from PIL import Image
@@ -118,6 +117,8 @@ class FastSAMPrompt:
118
117
  retina (bool, optional): Whether to use retina mask. Defaults to False.
119
118
  with_contours (bool, optional): Whether to plot contours. Defaults to True.
120
119
  """
120
+ import matplotlib.pyplot as plt
121
+
121
122
  pbar = TQDM(annotations, total=len(annotations))
122
123
  for ann in pbar:
123
124
  result_name = os.path.basename(ann.path)
@@ -202,6 +203,8 @@ class FastSAMPrompt:
202
203
  target_height (int, optional): Target height for resizing. Defaults to 960.
203
204
  target_width (int, optional): Target width for resizing. Defaults to 960.
204
205
  """
206
+ import matplotlib.pyplot as plt
207
+
205
208
  n, h, w = annotation.shape # batch, height, width
206
209
 
207
210
  areas = np.sum(annotation, axis=(1, 2))
@@ -125,7 +125,7 @@ class RTDETRValidator(DetectionValidator):
125
125
  bbox = ops.xywh2xyxy(bbox) # target boxes
126
126
  bbox[..., [0, 2]] *= ori_shape[1] # native-space pred
127
127
  bbox[..., [1, 3]] *= ori_shape[0] # native-space pred
128
- return dict(cls=cls, bbox=bbox, ori_shape=ori_shape, imgsz=imgsz, ratio_pad=ratio_pad)
128
+ return {"cls": cls, "bbox": bbox, "ori_shape": ori_shape, "imgsz": imgsz, "ratio_pad": ratio_pad}
129
129
 
130
130
  def _prepare_pred(self, pred, pbatch):
131
131
  """Prepares and returns a batch with transformed bounding boxes and class labels."""
@@ -584,9 +584,9 @@ class TinyViT(nn.Module):
584
584
  img_size (int, optional): The input image size. Defaults to 224.
585
585
  in_chans (int, optional): Number of input channels. Defaults to 3.
586
586
  num_classes (int, optional): Number of classification classes. Defaults to 1000.
587
- embed_dims (List[int], optional): List of embedding dimensions for each layer. Defaults to [96, 192, 384, 768].
587
+ embed_dims (List[int], optional): List of embedding dimensions per layer. Defaults to [96, 192, 384, 768].
588
588
  depths (List[int], optional): List of depths for each layer. Defaults to [2, 2, 6, 2].
589
- num_heads (List[int], optional): List of number of attention heads for each layer. Defaults to [3, 6, 12, 24].
589
+ num_heads (List[int], optional): List of number of attention heads per layer. Defaults to [3, 6, 12, 24].
590
590
  window_sizes (List[int], optional): List of window sizes for each layer. Defaults to [7, 7, 14, 7].
591
591
  mlp_ratio (float, optional): Ratio of MLP hidden dimension to embedding dimension. Defaults to 4.
592
592
  drop_rate (float, optional): Dropout rate. Defaults to 0.
@@ -222,7 +222,7 @@ class Attention(nn.Module):
222
222
  downsample_rate (int, optional): The factor by which the internal dimensions are downsampled. Defaults to 1.
223
223
 
224
224
  Raises:
225
- AssertionError: If 'num_heads' does not evenly divide the internal dimension (embedding_dim / downsample_rate).
225
+ AssertionError: If 'num_heads' does not evenly divide the internal dim (embedding_dim / downsample_rate).
226
226
  """
227
227
  super().__init__()
228
228
  self.embedding_dim = embedding_dim
@@ -11,7 +11,6 @@ segmentation tasks.
11
11
  import numpy as np
12
12
  import torch
13
13
  import torch.nn.functional as F
14
- import torchvision
15
14
 
16
15
  from ultralytics.data.augment import LetterBox
17
16
  from ultralytics.engine.predictor import BasePredictor
@@ -128,10 +127,10 @@ class Predictor(BasePredictor):
128
127
  Args:
129
128
  im (torch.Tensor): The preprocessed input image in tensor format, with shape (N, C, H, W).
130
129
  bboxes (np.ndarray | List, optional): Bounding boxes with shape (N, 4), in XYXY format.
131
- points (np.ndarray | List, optional): Points indicating object locations with shape (N, 2), in pixel coordinates.
132
- labels (np.ndarray | List, optional): Labels for point prompts, shape (N, ). 1 for foreground and 0 for background.
133
- masks (np.ndarray, optional): Low-resolution masks from previous predictions. Shape should be (N, H, W). For SAM, H=W=256.
134
- multimask_output (bool, optional): Flag to return multiple masks. Helpful for ambiguous prompts. Defaults to False.
130
+ points (np.ndarray | List, optional): Points indicating object locations with shape (N, 2), in pixels.
131
+ labels (np.ndarray | List, optional): Labels for point prompts, shape (N, ). 1 = foreground, 0 = background.
132
+ masks (np.ndarray, optional): Low-resolution masks from previous predictions shape (N,H,W). For SAM H=W=256.
133
+ multimask_output (bool, optional): Flag to return multiple masks. Helpful for ambiguous prompts.
135
134
 
136
135
  Returns:
137
136
  (tuple): Contains the following three elements.
@@ -157,10 +156,10 @@ class Predictor(BasePredictor):
157
156
  Args:
158
157
  im (torch.Tensor): The preprocessed input image in tensor format, with shape (N, C, H, W).
159
158
  bboxes (np.ndarray | List, optional): Bounding boxes with shape (N, 4), in XYXY format.
160
- points (np.ndarray | List, optional): Points indicating object locations with shape (N, 2), in pixel coordinates.
161
- labels (np.ndarray | List, optional): Labels for point prompts, shape (N, ). 1 for foreground and 0 for background.
162
- masks (np.ndarray, optional): Low-resolution masks from previous predictions. Shape should be (N, H, W). For SAM, H=W=256.
163
- multimask_output (bool, optional): Flag to return multiple masks. Helpful for ambiguous prompts. Defaults to False.
159
+ points (np.ndarray | List, optional): Points indicating object locations with shape (N, 2), in pixels.
160
+ labels (np.ndarray | List, optional): Labels for point prompts, shape (N, ). 1 = foreground, 0 = background.
161
+ masks (np.ndarray, optional): Low-resolution masks from previous predictions shape (N,H,W). For SAM H=W=256.
162
+ multimask_output (bool, optional): Flag to return multiple masks. Helpful for ambiguous prompts.
164
163
 
165
164
  Returns:
166
165
  (tuple): Contains the following three elements.
@@ -231,7 +230,7 @@ class Predictor(BasePredictor):
231
230
  im (torch.Tensor): Input tensor representing the preprocessed image with dimensions (N, C, H, W).
232
231
  crop_n_layers (int): Specifies the number of layers for additional mask predictions on image crops.
233
232
  Each layer produces 2**i_layer number of image crops.
234
- crop_overlap_ratio (float): Determines the extent of overlap between crops. Scaled down in subsequent layers.
233
+ crop_overlap_ratio (float): Determines the overlap between crops. Scaled down in subsequent layers.
235
234
  crop_downscale_factor (int): Scaling factor for the number of sampled points-per-side in each layer.
236
235
  point_grids (list[np.ndarray], optional): Custom grids for point sampling normalized to [0,1].
237
236
  Used in the nth crop layer.
@@ -241,11 +240,13 @@ class Predictor(BasePredictor):
241
240
  conf_thres (float): Confidence threshold [0,1] for filtering based on the model's mask quality prediction.
242
241
  stability_score_thresh (float): Stability threshold [0,1] for mask filtering based on mask stability.
243
242
  stability_score_offset (float): Offset value for calculating stability score.
244
- crop_nms_thresh (float): IoU cutoff for Non-Maximum Suppression (NMS) to remove duplicate masks between crops.
243
+ crop_nms_thresh (float): IoU cutoff for NMS to remove duplicate masks between crops.
245
244
 
246
245
  Returns:
247
246
  (tuple): A tuple containing segmented masks, confidence scores, and bounding boxes.
248
247
  """
248
+ import torchvision # scope for faster 'import ultralytics'
249
+
249
250
  self.segment_all = True
250
251
  ih, iw = im.shape[2:]
251
252
  crop_regions, layer_idxs = generate_crop_boxes((ih, iw), crop_n_layers, crop_overlap_ratio)
@@ -350,8 +351,8 @@ class Predictor(BasePredictor):
350
351
  """
351
352
  Post-processes SAM's inference outputs to generate object detection masks and bounding boxes.
352
353
 
353
- The method scales masks and boxes to the original image size and applies a threshold to the mask predictions. The
354
- SAM model uses advanced architecture and promptable segmentation tasks to achieve real-time performance.
354
+ The method scales masks and boxes to the original image size and applies a threshold to the mask predictions.
355
+ The SAM model uses advanced architecture and promptable segmentation tasks to achieve real-time performance.
355
356
 
356
357
  Args:
357
358
  preds (tuple): The output from SAM model inference, containing masks, scores, and optional bounding boxes.
@@ -449,6 +450,8 @@ class Predictor(BasePredictor):
449
450
  - new_masks (torch.Tensor): The processed masks with small regions removed. Shape is (N, H, W).
450
451
  - keep (List[int]): The indices of the remaining masks post-NMS, which can be used to filter the boxes.
451
452
  """
453
+ import torchvision # scope for faster 'import ultralytics'
454
+
452
455
  if len(masks) == 0:
453
456
  return masks
454
457
 
@@ -1,7 +1,6 @@
1
1
  # Ultralytics YOLO 🚀, AGPL-3.0 license
2
2
 
3
3
  import torch
4
- import torchvision
5
4
 
6
5
  from ultralytics.data import ClassificationDataset, build_dataloader
7
6
  from ultralytics.engine.trainer import BaseTrainer
@@ -59,6 +58,8 @@ class ClassificationTrainer(BaseTrainer):
59
58
 
60
59
  def setup_model(self):
61
60
  """Load, create or download model for any task."""
61
+ import torchvision # scope for faster 'import ultralytics'
62
+
62
63
  if isinstance(self.model, torch.nn.Module): # if model is loaded beforehand. No setup needed
63
64
  return
64
65
 
@@ -106,7 +106,7 @@ class DetectionValidator(BaseValidator):
106
106
  if len(cls):
107
107
  bbox = ops.xywh2xyxy(bbox) * torch.tensor(imgsz, device=self.device)[[1, 0, 1, 0]] # target boxes
108
108
  ops.scale_boxes(imgsz, bbox, ori_shape, ratio_pad=ratio_pad) # native-space labels
109
- return dict(cls=cls, bbox=bbox, ori_shape=ori_shape, imgsz=imgsz, ratio_pad=ratio_pad)
109
+ return {"cls": cls, "bbox": bbox, "ori_shape": ori_shape, "imgsz": imgsz, "ratio_pad": ratio_pad}
110
110
 
111
111
  def _prepare_pred(self, pred, pbatch):
112
112
  """Prepares a batch of images and annotations for validation."""
@@ -5,7 +5,7 @@ from pathlib import Path
5
5
  from ultralytics.engine.model import Model
6
6
  from ultralytics.models import yolo
7
7
  from ultralytics.nn.tasks import ClassificationModel, DetectionModel, OBBModel, PoseModel, SegmentationModel, WorldModel
8
- from ultralytics.utils import yaml_load, ROOT
8
+ from ultralytics.utils import ROOT, yaml_load
9
9
 
10
10
 
11
11
  class YOLO(Model):
@@ -78,7 +78,7 @@ class OBBValidator(DetectionValidator):
78
78
  if len(cls):
79
79
  bbox[..., :4].mul_(torch.tensor(imgsz, device=self.device)[[1, 0, 1, 0]]) # target boxes
80
80
  ops.scale_boxes(imgsz, bbox, ori_shape, ratio_pad=ratio_pad, xywh=True) # native-space labels
81
- return dict(cls=cls, bbox=bbox, ori_shape=ori_shape, imgsz=imgsz, ratio_pad=ratio_pad)
81
+ return {"cls": cls, "bbox": bbox, "ori_shape": ori_shape, "imgsz": imgsz, "ratio_pad": ratio_pad}
82
82
 
83
83
  def _prepare_pred(self, pred, pbatch):
84
84
  """Prepares and returns a batch for OBB validation with scaled and padded bounding boxes."""
@@ -1,8 +1,8 @@
1
- from ultralytics.data import build_yolo_dataset, build_grounding, YOLOConcatDataset
1
+ from ultralytics.data import YOLOConcatDataset, build_grounding, build_yolo_dataset
2
2
  from ultralytics.data.utils import check_det_dataset
3
3
  from ultralytics.models.yolo.world import WorldTrainer
4
- from ultralytics.utils.torch_utils import de_parallel
5
4
  from ultralytics.utils import DEFAULT_CFG
5
+ from ultralytics.utils.torch_utils import de_parallel
6
6
 
7
7
 
8
8
  class WorldTrainerFromScratch(WorldTrainer):
@@ -24,27 +24,27 @@ from .block import (
24
24
  C3TR,
25
25
  DFL,
26
26
  SPP,
27
+ SPPELAN,
27
28
  SPPF,
29
+ ADown,
30
+ BNContrastiveHead,
28
31
  Bottleneck,
29
32
  BottleneckCSP,
30
33
  C2f,
31
34
  C2fAttn,
32
- ImagePoolingAttn,
33
35
  C3Ghost,
34
36
  C3x,
37
+ CBFuse,
38
+ CBLinear,
39
+ ContrastiveHead,
35
40
  GhostBottleneck,
36
41
  HGBlock,
37
42
  HGStem,
43
+ ImagePoolingAttn,
38
44
  Proto,
39
45
  RepC3,
40
- ResNetLayer,
41
- ContrastiveHead,
42
- BNContrastiveHead,
43
46
  RepNCSPELAN4,
44
- ADown,
45
- SPPELAN,
46
- CBFuse,
47
- CBLinear,
47
+ ResNetLayer,
48
48
  Silence,
49
49
  )
50
50
  from .conv import (
@@ -8,7 +8,7 @@ import torch.nn as nn
8
8
  from torch.nn.init import constant_, xavier_uniform_
9
9
 
10
10
  from ultralytics.utils.tal import TORCH_1_10, dist2bbox, dist2rbox, make_anchors
11
- from .block import DFL, Proto, ContrastiveHead, BNContrastiveHead
11
+ from .block import DFL, BNContrastiveHead, ContrastiveHead, Proto
12
12
  from .conv import Conv
13
13
  from .transformer import MLP, DeformableTransformerDecoder, DeformableTransformerDecoderLayer
14
14
  from .utils import bias_init_with_prob, linear_init
ultralytics/nn/tasks.py CHANGED
@@ -15,14 +15,17 @@ from ultralytics.nn.modules import (
15
15
  C3TR,
16
16
  OBB,
17
17
  SPP,
18
+ SPPELAN,
18
19
  SPPF,
20
+ ADown,
19
21
  Bottleneck,
20
22
  BottleneckCSP,
21
23
  C2f,
22
24
  C2fAttn,
23
- ImagePoolingAttn,
24
25
  C3Ghost,
25
26
  C3x,
27
+ CBFuse,
28
+ CBLinear,
26
29
  Classify,
27
30
  Concat,
28
31
  Conv,
@@ -36,19 +39,16 @@ from ultralytics.nn.modules import (
36
39
  GhostConv,
37
40
  HGBlock,
38
41
  HGStem,
42
+ ImagePoolingAttn,
39
43
  Pose,
40
44
  RepC3,
41
45
  RepConv,
46
+ RepNCSPELAN4,
42
47
  ResNetLayer,
43
48
  RTDETRDecoder,
44
49
  Segment,
45
- WorldDetect,
46
- RepNCSPELAN4,
47
- ADown,
48
- SPPELAN,
49
- CBFuse,
50
- CBLinear,
51
50
  Silence,
51
+ WorldDetect,
52
52
  )
53
53
  from ultralytics.utils import DEFAULT_CFG_DICT, DEFAULT_CFG_KEYS, LOGGER, colorstr, emojis, yaml_load
54
54
  from ultralytics.utils.checks import check_requirements, check_suffix, check_yaml
@@ -30,6 +30,7 @@ class Heatmap:
30
30
  self.imw = None
31
31
  self.imh = None
32
32
  self.im0 = None
33
+ self.tf = 2
33
34
  self.view_in_counts = True
34
35
  self.view_out_counts = True
35
36
 
@@ -56,11 +57,9 @@ class Heatmap:
56
57
  self.out_counts = 0
57
58
  self.count_ids = []
58
59
  self.class_wise_count = {}
59
- self.count_txt_thickness = 0
60
- self.count_txt_color = (255, 255, 255)
61
- self.line_color = (255, 255, 255)
60
+ self.count_txt_color = (0, 0, 0)
61
+ self.count_bg_color = (255, 255, 255)
62
62
  self.cls_txtdisplay_gap = 50
63
- self.fontsize = 0.6
64
63
 
65
64
  # Decay factor
66
65
  self.decay_factor = 0.99
@@ -79,16 +78,14 @@ class Heatmap:
79
78
  view_in_counts=True,
80
79
  view_out_counts=True,
81
80
  count_reg_pts=None,
82
- count_txt_thickness=2,
83
- count_txt_color=(255, 255, 255),
84
- fontsize=0.8,
85
- line_color=(255, 255, 255),
81
+ count_txt_color=(0, 0, 0),
82
+ count_bg_color=(255, 255, 255),
86
83
  count_reg_color=(255, 0, 255),
87
84
  region_thickness=5,
88
85
  line_dist_thresh=15,
86
+ line_thickness=2,
89
87
  decay_factor=0.99,
90
88
  shape="circle",
91
- cls_txtdisplay_gap=50,
92
89
  ):
93
90
  """
94
91
  Configures the heatmap colormap, width, height and display parameters.
@@ -98,22 +95,21 @@ class Heatmap:
98
95
  imw (int): The width of the frame.
99
96
  imh (int): The height of the frame.
100
97
  classes_names (dict): Classes names
98
+ line_thickness (int): Line thickness for bounding boxes.
101
99
  heatmap_alpha (float): alpha value for heatmap display
102
100
  view_img (bool): Flag indicating frame display
103
101
  view_in_counts (bool): Flag to control whether to display the incounts on video stream.
104
102
  view_out_counts (bool): Flag to control whether to display the outcounts on video stream.
105
103
  count_reg_pts (list): Object counting region points
106
- count_txt_thickness (int): Text thickness for object counting display
107
104
  count_txt_color (RGB color): count text color value
108
- fontsize (float): Text display font size
109
- line_color (RGB color): count highlighter line color
105
+ count_bg_color (RGB color): count highlighter line color
110
106
  count_reg_color (RGB color): Color of object counting region
111
107
  region_thickness (int): Object counting Region thickness
112
108
  line_dist_thresh (int): Euclidean Distance threshold for line counter
113
109
  decay_factor (float): value for removing heatmap area after object passed
114
110
  shape (str): Heatmap shape, rect or circle shape supported
115
- cls_txtdisplay_gap (int): Display gap between each class count
116
111
  """
112
+ self.tf = line_thickness
117
113
  self.names = classes_names
118
114
  self.imw = imw
119
115
  self.imh = imh
@@ -141,16 +137,13 @@ class Heatmap:
141
137
  # Heatmap new frame
142
138
  self.heatmap = np.zeros((int(self.imh), int(self.imw)), dtype=np.float32)
143
139
 
144
- self.count_txt_thickness = count_txt_thickness
145
140
  self.count_txt_color = count_txt_color
146
- self.fontsize = fontsize
147
- self.line_color = line_color
141
+ self.count_bg_color = count_bg_color
148
142
  self.region_color = count_reg_color
149
143
  self.region_thickness = region_thickness
150
144
  self.decay_factor = decay_factor
151
145
  self.line_dist_thresh = line_dist_thresh
152
146
  self.shape = shape
153
- self.cls_txtdisplay_gap = cls_txtdisplay_gap
154
147
 
155
148
  # shape of heatmap, if not selected
156
149
  if self.shape not in {"circle", "rect"}:
@@ -185,7 +178,7 @@ class Heatmap:
185
178
  return im0
186
179
  self.heatmap *= self.decay_factor # decay factor
187
180
  self.extract_results(tracks)
188
- self.annotator = Annotator(self.im0, self.count_txt_thickness, None)
181
+ self.annotator = Annotator(self.im0, self.tf, None)
189
182
 
190
183
  if self.count_reg_pts is not None:
191
184
  # Draw counting region
@@ -239,11 +232,8 @@ class Heatmap:
239
232
 
240
233
  # Count objects using line
241
234
  elif len(self.count_reg_pts) == 2:
242
- is_inside = (box[0] - prev_position[0]) * (self.counting_region.centroid.x - prev_position[0]) > 0
243
-
244
- if prev_position is not None and is_inside and track_id not in self.count_ids:
235
+ if prev_position is not None and track_id not in self.count_ids:
245
236
  distance = Point(track_line[-1]).distance(self.counting_region)
246
-
247
237
  if distance < self.line_dist_thresh and track_id not in self.count_ids:
248
238
  self.count_ids.append(track_id)
249
239
 
@@ -293,11 +283,8 @@ class Heatmap:
293
283
  if self.count_reg_pts is not None and label is not None:
294
284
  self.annotator.display_counts(
295
285
  counts=label,
296
- tf=self.count_txt_thickness,
297
- fontScale=self.fontsize,
298
- txt_color=self.count_txt_color,
299
- line_color=self.line_color,
300
- classwise_txtgap=self.cls_txtdisplay_gap,
286
+ count_txt_color=self.count_txt_color,
287
+ count_bg_color=self.count_bg_color,
301
288
  )
302
289
 
303
290
  self.im0 = cv2.addWeighted(self.im0, 1 - self.heatmap_alpha, heatmap_colored, self.heatmap_alpha, 0)