dgenerate-ultralytics-headless 8.3.143__py3-none-any.whl → 8.3.145__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 (148) hide show
  1. {dgenerate_ultralytics_headless-8.3.143.dist-info → dgenerate_ultralytics_headless-8.3.145.dist-info}/METADATA +2 -2
  2. dgenerate_ultralytics_headless-8.3.145.dist-info/RECORD +272 -0
  3. tests/conftest.py +7 -24
  4. tests/test_cli.py +1 -1
  5. tests/test_cuda.py +7 -2
  6. tests/test_engine.py +7 -8
  7. tests/test_exports.py +16 -16
  8. tests/test_integrations.py +1 -1
  9. tests/test_solutions.py +11 -11
  10. ultralytics/__init__.py +1 -1
  11. ultralytics/cfg/__init__.py +16 -13
  12. ultralytics/data/annotator.py +6 -5
  13. ultralytics/data/augment.py +127 -126
  14. ultralytics/data/base.py +54 -51
  15. ultralytics/data/build.py +47 -23
  16. ultralytics/data/converter.py +47 -43
  17. ultralytics/data/dataset.py +51 -50
  18. ultralytics/data/loaders.py +77 -44
  19. ultralytics/data/split.py +22 -9
  20. ultralytics/data/split_dota.py +63 -39
  21. ultralytics/data/utils.py +59 -39
  22. ultralytics/engine/exporter.py +79 -27
  23. ultralytics/engine/model.py +52 -51
  24. ultralytics/engine/predictor.py +37 -28
  25. ultralytics/engine/results.py +191 -161
  26. ultralytics/engine/trainer.py +36 -19
  27. ultralytics/engine/tuner.py +12 -9
  28. ultralytics/engine/validator.py +7 -9
  29. ultralytics/hub/__init__.py +11 -13
  30. ultralytics/hub/auth.py +22 -2
  31. ultralytics/hub/google/__init__.py +19 -19
  32. ultralytics/hub/session.py +37 -51
  33. ultralytics/hub/utils.py +19 -5
  34. ultralytics/models/fastsam/model.py +30 -12
  35. ultralytics/models/fastsam/predict.py +5 -6
  36. ultralytics/models/fastsam/utils.py +3 -3
  37. ultralytics/models/fastsam/val.py +10 -6
  38. ultralytics/models/nas/model.py +9 -5
  39. ultralytics/models/nas/predict.py +6 -6
  40. ultralytics/models/nas/val.py +3 -3
  41. ultralytics/models/rtdetr/model.py +7 -6
  42. ultralytics/models/rtdetr/predict.py +14 -7
  43. ultralytics/models/rtdetr/train.py +10 -4
  44. ultralytics/models/rtdetr/val.py +36 -9
  45. ultralytics/models/sam/amg.py +30 -12
  46. ultralytics/models/sam/build.py +22 -22
  47. ultralytics/models/sam/model.py +10 -9
  48. ultralytics/models/sam/modules/blocks.py +76 -80
  49. ultralytics/models/sam/modules/decoders.py +6 -8
  50. ultralytics/models/sam/modules/encoders.py +23 -26
  51. ultralytics/models/sam/modules/memory_attention.py +13 -1
  52. ultralytics/models/sam/modules/sam.py +57 -26
  53. ultralytics/models/sam/modules/tiny_encoder.py +232 -237
  54. ultralytics/models/sam/modules/transformer.py +13 -13
  55. ultralytics/models/sam/modules/utils.py +11 -19
  56. ultralytics/models/sam/predict.py +114 -101
  57. ultralytics/models/utils/loss.py +98 -77
  58. ultralytics/models/utils/ops.py +116 -67
  59. ultralytics/models/yolo/classify/predict.py +5 -5
  60. ultralytics/models/yolo/classify/train.py +32 -28
  61. ultralytics/models/yolo/classify/val.py +7 -8
  62. ultralytics/models/yolo/detect/predict.py +1 -0
  63. ultralytics/models/yolo/detect/train.py +15 -14
  64. ultralytics/models/yolo/detect/val.py +37 -36
  65. ultralytics/models/yolo/model.py +106 -23
  66. ultralytics/models/yolo/obb/predict.py +3 -4
  67. ultralytics/models/yolo/obb/train.py +14 -6
  68. ultralytics/models/yolo/obb/val.py +29 -23
  69. ultralytics/models/yolo/pose/predict.py +9 -8
  70. ultralytics/models/yolo/pose/train.py +24 -16
  71. ultralytics/models/yolo/pose/val.py +44 -26
  72. ultralytics/models/yolo/segment/predict.py +5 -5
  73. ultralytics/models/yolo/segment/train.py +11 -7
  74. ultralytics/models/yolo/segment/val.py +2 -2
  75. ultralytics/models/yolo/world/train.py +33 -23
  76. ultralytics/models/yolo/world/train_world.py +11 -3
  77. ultralytics/models/yolo/yoloe/predict.py +11 -11
  78. ultralytics/models/yolo/yoloe/train.py +73 -21
  79. ultralytics/models/yolo/yoloe/train_seg.py +10 -7
  80. ultralytics/models/yolo/yoloe/val.py +42 -18
  81. ultralytics/nn/autobackend.py +59 -15
  82. ultralytics/nn/modules/__init__.py +4 -4
  83. ultralytics/nn/modules/activation.py +4 -1
  84. ultralytics/nn/modules/block.py +178 -111
  85. ultralytics/nn/modules/conv.py +6 -5
  86. ultralytics/nn/modules/head.py +469 -121
  87. ultralytics/nn/modules/transformer.py +147 -58
  88. ultralytics/nn/tasks.py +227 -20
  89. ultralytics/nn/text_model.py +30 -33
  90. ultralytics/solutions/ai_gym.py +4 -6
  91. ultralytics/solutions/analytics.py +7 -4
  92. ultralytics/solutions/config.py +10 -10
  93. ultralytics/solutions/distance_calculation.py +11 -10
  94. ultralytics/solutions/heatmap.py +2 -2
  95. ultralytics/solutions/instance_segmentation.py +7 -4
  96. ultralytics/solutions/object_blurrer.py +3 -3
  97. ultralytics/solutions/object_counter.py +15 -11
  98. ultralytics/solutions/object_cropper.py +3 -2
  99. ultralytics/solutions/parking_management.py +29 -28
  100. ultralytics/solutions/queue_management.py +6 -6
  101. ultralytics/solutions/region_counter.py +10 -3
  102. ultralytics/solutions/security_alarm.py +3 -3
  103. ultralytics/solutions/similarity_search.py +85 -24
  104. ultralytics/solutions/solutions.py +189 -79
  105. ultralytics/solutions/speed_estimation.py +28 -22
  106. ultralytics/solutions/streamlit_inference.py +17 -12
  107. ultralytics/solutions/trackzone.py +4 -4
  108. ultralytics/trackers/basetrack.py +16 -23
  109. ultralytics/trackers/bot_sort.py +30 -20
  110. ultralytics/trackers/byte_tracker.py +70 -64
  111. ultralytics/trackers/track.py +4 -8
  112. ultralytics/trackers/utils/gmc.py +31 -58
  113. ultralytics/trackers/utils/kalman_filter.py +37 -37
  114. ultralytics/trackers/utils/matching.py +1 -1
  115. ultralytics/utils/__init__.py +105 -89
  116. ultralytics/utils/autobatch.py +16 -3
  117. ultralytics/utils/autodevice.py +54 -24
  118. ultralytics/utils/benchmarks.py +45 -29
  119. ultralytics/utils/callbacks/base.py +3 -3
  120. ultralytics/utils/callbacks/clearml.py +9 -9
  121. ultralytics/utils/callbacks/comet.py +67 -25
  122. ultralytics/utils/callbacks/dvc.py +7 -10
  123. ultralytics/utils/callbacks/mlflow.py +2 -5
  124. ultralytics/utils/callbacks/neptune.py +7 -13
  125. ultralytics/utils/callbacks/raytune.py +1 -1
  126. ultralytics/utils/callbacks/tensorboard.py +5 -6
  127. ultralytics/utils/callbacks/wb.py +14 -14
  128. ultralytics/utils/checks.py +14 -13
  129. ultralytics/utils/dist.py +5 -5
  130. ultralytics/utils/downloads.py +94 -67
  131. ultralytics/utils/errors.py +5 -5
  132. ultralytics/utils/export.py +61 -47
  133. ultralytics/utils/files.py +23 -22
  134. ultralytics/utils/instance.py +48 -52
  135. ultralytics/utils/loss.py +78 -40
  136. ultralytics/utils/metrics.py +186 -130
  137. ultralytics/utils/ops.py +186 -190
  138. ultralytics/utils/patches.py +15 -17
  139. ultralytics/utils/plotting.py +71 -27
  140. ultralytics/utils/tal.py +21 -15
  141. ultralytics/utils/torch_utils.py +53 -50
  142. ultralytics/utils/triton.py +5 -4
  143. ultralytics/utils/tuner.py +5 -5
  144. dgenerate_ultralytics_headless-8.3.143.dist-info/RECORD +0 -272
  145. {dgenerate_ultralytics_headless-8.3.143.dist-info → dgenerate_ultralytics_headless-8.3.145.dist-info}/WHEEL +0 -0
  146. {dgenerate_ultralytics_headless-8.3.143.dist-info → dgenerate_ultralytics_headless-8.3.145.dist-info}/entry_points.txt +0 -0
  147. {dgenerate_ultralytics_headless-8.3.143.dist-info → dgenerate_ultralytics_headless-8.3.145.dist-info}/licenses/LICENSE +0 -0
  148. {dgenerate_ultralytics_headless-8.3.143.dist-info → dgenerate_ultralytics_headless-8.3.145.dist-info}/top_level.txt +0 -0
@@ -2,6 +2,7 @@
2
2
 
3
3
  import os
4
4
  from pathlib import Path
5
+ from typing import List
5
6
 
6
7
  import numpy as np
7
8
  import torch
@@ -17,17 +18,38 @@ os.environ["KMP_DUPLICATE_LIB_OK"] = "TRUE" # Avoid OpenMP conflict on some sys
17
18
 
18
19
  class VisualAISearch(BaseSolution):
19
20
  """
20
- VisualAISearch leverages OpenCLIP to generate high-quality image and text embeddings, aligning them in a shared
21
- semantic space. It then uses FAISS to perform fast and scalable similarity-based retrieval, allowing users to search
22
- large collections of images using natural language queries with high accuracy and speed.
21
+ A semantic image search system that leverages OpenCLIP for generating high-quality image and text embeddings and
22
+ FAISS for fast similarity-based retrieval.
23
+
24
+ This class aligns image and text embeddings in a shared semantic space, enabling users to search large collections
25
+ of images using natural language queries with high accuracy and speed.
23
26
 
24
27
  Attributes:
25
28
  data (str): Directory containing images.
26
29
  device (str): Computation device, e.g., 'cpu' or 'cuda'.
30
+ faiss_index (str): Path to the FAISS index file.
31
+ data_path_npy (str): Path to the numpy file storing image paths.
32
+ model_name (str): Name of the CLIP model to use.
33
+ data_dir (Path): Path object for the data directory.
34
+ model: Loaded CLIP model.
35
+ preprocess: CLIP preprocessing function.
36
+ index: FAISS index for similarity search.
37
+ image_paths (List[str]): List of image file paths.
38
+
39
+ Methods:
40
+ extract_image_feature: Extract CLIP embedding from an image.
41
+ extract_text_feature: Extract CLIP embedding from text.
42
+ load_or_build_index: Load existing FAISS index or build new one.
43
+ search: Perform semantic search for similar images.
44
+
45
+ Examples:
46
+ Initialize and search for images
47
+ >>> searcher = VisualAISearch(data="path/to/images", device="cuda")
48
+ >>> results = searcher.search("a cat sitting on a chair", k=10)
27
49
  """
28
50
 
29
51
  def __init__(self, **kwargs):
30
- """Initializes the VisualAISearch class with the FAISS index file and CLIP model."""
52
+ """Initialize the VisualAISearch class with FAISS index and CLIP model."""
31
53
  super().__init__(**kwargs)
32
54
  check_requirements(["git+https://github.com/ultralytics/CLIP.git", "faiss-cpu"])
33
55
 
@@ -55,21 +77,27 @@ class VisualAISearch(BaseSolution):
55
77
 
56
78
  self.load_or_build_index()
57
79
 
58
- def extract_image_feature(self, path):
59
- """Extract CLIP image embedding."""
80
+ def extract_image_feature(self, path: Path) -> np.ndarray:
81
+ """Extract CLIP image embedding from the given image path."""
60
82
  image = Image.open(path)
61
83
  tensor = self.preprocess(image).unsqueeze(0).to(self.device)
62
84
  with torch.no_grad():
63
85
  return self.model.encode_image(tensor).cpu().numpy()
64
86
 
65
- def extract_text_feature(self, text):
66
- """Extract CLIP text embedding."""
87
+ def extract_text_feature(self, text: str) -> np.ndarray:
88
+ """Extract CLIP text embedding from the given text query."""
67
89
  tokens = self.clip.tokenize([text]).to(self.device)
68
90
  with torch.no_grad():
69
91
  return self.model.encode_text(tokens).cpu().numpy()
70
92
 
71
93
  def load_or_build_index(self):
72
- """Loads FAISS index or builds a new one from image features."""
94
+ """
95
+ Load existing FAISS index or build a new one from image features.
96
+
97
+ Checks if FAISS index and image paths exist on disk. If found, loads them directly. Otherwise, builds a new
98
+ index by extracting features from all images in the data directory, normalizes the features, and saves both the
99
+ index and image paths for future use.
100
+ """
73
101
  # Check if the FAISS index and corresponding image paths already exist
74
102
  if Path(self.faiss_index).exists() and Path(self.data_path_npy).exists():
75
103
  self.LOGGER.info("Loading existing FAISS index...")
@@ -107,8 +135,23 @@ class VisualAISearch(BaseSolution):
107
135
 
108
136
  self.LOGGER.info(f"Indexed {len(self.image_paths)} images.")
109
137
 
110
- def search(self, query, k=30, similarity_thresh=0.1):
111
- """Returns top-k semantically similar images to the given query."""
138
+ def search(self, query: str, k: int = 30, similarity_thresh: float = 0.1) -> List[str]:
139
+ """
140
+ Return top-k semantically similar images to the given query.
141
+
142
+ Args:
143
+ query (str): Natural language text query to search for.
144
+ k (int, optional): Maximum number of results to return.
145
+ similarity_thresh (float, optional): Minimum similarity threshold for filtering results.
146
+
147
+ Returns:
148
+ (List[str]): List of image filenames ranked by similarity score.
149
+
150
+ Examples:
151
+ Search for images matching a query
152
+ >>> searcher = VisualAISearch(data="images")
153
+ >>> results = searcher.search("red car", k=5, similarity_thresh=0.2)
154
+ """
112
155
  text_feat = self.extract_text_feature(query).astype("float32")
113
156
  self.faiss.normalize_L2(text_feat)
114
157
 
@@ -124,24 +167,42 @@ class VisualAISearch(BaseSolution):
124
167
 
125
168
  return [r[0] for r in results]
126
169
 
127
- def __call__(self, query):
128
- """Direct call for search function."""
170
+ def __call__(self, query: str) -> List[str]:
171
+ """Direct call interface for the search function."""
129
172
  return self.search(query)
130
173
 
131
174
 
132
175
  class SearchApp:
133
176
  """
134
- A Flask-based web interface powers the semantic image search experience, enabling users to input natural language
135
- queries and instantly view the most relevant images retrieved from the indexed database—all through a clean,
136
- responsive, and easily customizable frontend.
177
+ A Flask-based web interface for semantic image search with natural language queries.
178
+
179
+ This class provides a clean, responsive frontend that enables users to input natural language queries and
180
+ instantly view the most relevant images retrieved from the indexed database.
137
181
 
138
- Args:
139
- data (str): Path to images to index and search.
140
- device (str): Device to run inference on (e.g. 'cpu', 'cuda').
182
+ Attributes:
183
+ render_template: Flask template rendering function.
184
+ request: Flask request object.
185
+ searcher (VisualAISearch): Instance of the VisualAISearch class.
186
+ app (Flask): Flask application instance.
187
+
188
+ Methods:
189
+ index: Process user queries and display search results.
190
+ run: Start the Flask web application.
191
+
192
+ Examples:
193
+ Start a search application
194
+ >>> app = SearchApp(data="path/to/images", device="cuda")
195
+ >>> app.run(debug=True)
141
196
  """
142
197
 
143
- def __init__(self, data="images", device=None):
144
- """Initialization of the VisualAISearch class for performing semantic image search."""
198
+ def __init__(self, data: str = "images", device: str = None):
199
+ """
200
+ Initialize the SearchApp with VisualAISearch backend.
201
+
202
+ Args:
203
+ data (str, optional): Path to directory containing images to index and search.
204
+ device (str, optional): Device to run inference on (e.g. 'cpu', 'cuda').
205
+ """
145
206
  check_requirements("flask")
146
207
  from flask import Flask, render_template, request
147
208
 
@@ -157,13 +218,13 @@ class SearchApp:
157
218
  self.app.add_url_rule("/", view_func=self.index, methods=["GET", "POST"])
158
219
 
159
220
  def index(self):
160
- """Function to process the user query and display output."""
221
+ """Process user query and display search results in the web interface."""
161
222
  results = []
162
223
  if self.request.method == "POST":
163
224
  query = self.request.form.get("query", "").strip()
164
225
  results = self.searcher(query)
165
226
  return self.render_template("similarity-search.html", results=results)
166
227
 
167
- def run(self, debug=False):
168
- """Runs the Flask web app."""
228
+ def run(self, debug: bool = False):
229
+ """Start the Flask web application server."""
169
230
  self.app.run(debug=debug)