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.
- {dgenerate_ultralytics_headless-8.3.143.dist-info → dgenerate_ultralytics_headless-8.3.145.dist-info}/METADATA +2 -2
- dgenerate_ultralytics_headless-8.3.145.dist-info/RECORD +272 -0
- tests/conftest.py +7 -24
- tests/test_cli.py +1 -1
- tests/test_cuda.py +7 -2
- tests/test_engine.py +7 -8
- tests/test_exports.py +16 -16
- tests/test_integrations.py +1 -1
- tests/test_solutions.py +11 -11
- ultralytics/__init__.py +1 -1
- ultralytics/cfg/__init__.py +16 -13
- ultralytics/data/annotator.py +6 -5
- ultralytics/data/augment.py +127 -126
- ultralytics/data/base.py +54 -51
- ultralytics/data/build.py +47 -23
- ultralytics/data/converter.py +47 -43
- ultralytics/data/dataset.py +51 -50
- ultralytics/data/loaders.py +77 -44
- ultralytics/data/split.py +22 -9
- ultralytics/data/split_dota.py +63 -39
- ultralytics/data/utils.py +59 -39
- ultralytics/engine/exporter.py +79 -27
- ultralytics/engine/model.py +52 -51
- ultralytics/engine/predictor.py +37 -28
- ultralytics/engine/results.py +191 -161
- ultralytics/engine/trainer.py +36 -19
- ultralytics/engine/tuner.py +12 -9
- ultralytics/engine/validator.py +7 -9
- ultralytics/hub/__init__.py +11 -13
- ultralytics/hub/auth.py +22 -2
- ultralytics/hub/google/__init__.py +19 -19
- ultralytics/hub/session.py +37 -51
- ultralytics/hub/utils.py +19 -5
- ultralytics/models/fastsam/model.py +30 -12
- ultralytics/models/fastsam/predict.py +5 -6
- ultralytics/models/fastsam/utils.py +3 -3
- ultralytics/models/fastsam/val.py +10 -6
- ultralytics/models/nas/model.py +9 -5
- ultralytics/models/nas/predict.py +6 -6
- ultralytics/models/nas/val.py +3 -3
- ultralytics/models/rtdetr/model.py +7 -6
- ultralytics/models/rtdetr/predict.py +14 -7
- ultralytics/models/rtdetr/train.py +10 -4
- ultralytics/models/rtdetr/val.py +36 -9
- ultralytics/models/sam/amg.py +30 -12
- ultralytics/models/sam/build.py +22 -22
- ultralytics/models/sam/model.py +10 -9
- ultralytics/models/sam/modules/blocks.py +76 -80
- ultralytics/models/sam/modules/decoders.py +6 -8
- ultralytics/models/sam/modules/encoders.py +23 -26
- ultralytics/models/sam/modules/memory_attention.py +13 -1
- ultralytics/models/sam/modules/sam.py +57 -26
- ultralytics/models/sam/modules/tiny_encoder.py +232 -237
- ultralytics/models/sam/modules/transformer.py +13 -13
- ultralytics/models/sam/modules/utils.py +11 -19
- ultralytics/models/sam/predict.py +114 -101
- ultralytics/models/utils/loss.py +98 -77
- ultralytics/models/utils/ops.py +116 -67
- ultralytics/models/yolo/classify/predict.py +5 -5
- ultralytics/models/yolo/classify/train.py +32 -28
- ultralytics/models/yolo/classify/val.py +7 -8
- ultralytics/models/yolo/detect/predict.py +1 -0
- ultralytics/models/yolo/detect/train.py +15 -14
- ultralytics/models/yolo/detect/val.py +37 -36
- ultralytics/models/yolo/model.py +106 -23
- ultralytics/models/yolo/obb/predict.py +3 -4
- ultralytics/models/yolo/obb/train.py +14 -6
- ultralytics/models/yolo/obb/val.py +29 -23
- ultralytics/models/yolo/pose/predict.py +9 -8
- ultralytics/models/yolo/pose/train.py +24 -16
- ultralytics/models/yolo/pose/val.py +44 -26
- ultralytics/models/yolo/segment/predict.py +5 -5
- ultralytics/models/yolo/segment/train.py +11 -7
- ultralytics/models/yolo/segment/val.py +2 -2
- ultralytics/models/yolo/world/train.py +33 -23
- ultralytics/models/yolo/world/train_world.py +11 -3
- ultralytics/models/yolo/yoloe/predict.py +11 -11
- ultralytics/models/yolo/yoloe/train.py +73 -21
- ultralytics/models/yolo/yoloe/train_seg.py +10 -7
- ultralytics/models/yolo/yoloe/val.py +42 -18
- ultralytics/nn/autobackend.py +59 -15
- ultralytics/nn/modules/__init__.py +4 -4
- ultralytics/nn/modules/activation.py +4 -1
- ultralytics/nn/modules/block.py +178 -111
- ultralytics/nn/modules/conv.py +6 -5
- ultralytics/nn/modules/head.py +469 -121
- ultralytics/nn/modules/transformer.py +147 -58
- ultralytics/nn/tasks.py +227 -20
- ultralytics/nn/text_model.py +30 -33
- ultralytics/solutions/ai_gym.py +4 -6
- ultralytics/solutions/analytics.py +7 -4
- ultralytics/solutions/config.py +10 -10
- ultralytics/solutions/distance_calculation.py +11 -10
- ultralytics/solutions/heatmap.py +2 -2
- ultralytics/solutions/instance_segmentation.py +7 -4
- ultralytics/solutions/object_blurrer.py +3 -3
- ultralytics/solutions/object_counter.py +15 -11
- ultralytics/solutions/object_cropper.py +3 -2
- ultralytics/solutions/parking_management.py +29 -28
- ultralytics/solutions/queue_management.py +6 -6
- ultralytics/solutions/region_counter.py +10 -3
- ultralytics/solutions/security_alarm.py +3 -3
- ultralytics/solutions/similarity_search.py +85 -24
- ultralytics/solutions/solutions.py +189 -79
- ultralytics/solutions/speed_estimation.py +28 -22
- ultralytics/solutions/streamlit_inference.py +17 -12
- ultralytics/solutions/trackzone.py +4 -4
- ultralytics/trackers/basetrack.py +16 -23
- ultralytics/trackers/bot_sort.py +30 -20
- ultralytics/trackers/byte_tracker.py +70 -64
- ultralytics/trackers/track.py +4 -8
- ultralytics/trackers/utils/gmc.py +31 -58
- ultralytics/trackers/utils/kalman_filter.py +37 -37
- ultralytics/trackers/utils/matching.py +1 -1
- ultralytics/utils/__init__.py +105 -89
- ultralytics/utils/autobatch.py +16 -3
- ultralytics/utils/autodevice.py +54 -24
- ultralytics/utils/benchmarks.py +45 -29
- ultralytics/utils/callbacks/base.py +3 -3
- ultralytics/utils/callbacks/clearml.py +9 -9
- ultralytics/utils/callbacks/comet.py +67 -25
- ultralytics/utils/callbacks/dvc.py +7 -10
- ultralytics/utils/callbacks/mlflow.py +2 -5
- ultralytics/utils/callbacks/neptune.py +7 -13
- ultralytics/utils/callbacks/raytune.py +1 -1
- ultralytics/utils/callbacks/tensorboard.py +5 -6
- ultralytics/utils/callbacks/wb.py +14 -14
- ultralytics/utils/checks.py +14 -13
- ultralytics/utils/dist.py +5 -5
- ultralytics/utils/downloads.py +94 -67
- ultralytics/utils/errors.py +5 -5
- ultralytics/utils/export.py +61 -47
- ultralytics/utils/files.py +23 -22
- ultralytics/utils/instance.py +48 -52
- ultralytics/utils/loss.py +78 -40
- ultralytics/utils/metrics.py +186 -130
- ultralytics/utils/ops.py +186 -190
- ultralytics/utils/patches.py +15 -17
- ultralytics/utils/plotting.py +71 -27
- ultralytics/utils/tal.py +21 -15
- ultralytics/utils/torch_utils.py +53 -50
- ultralytics/utils/triton.py +5 -4
- ultralytics/utils/tuner.py +5 -5
- dgenerate_ultralytics_headless-8.3.143.dist-info/RECORD +0 -272
- {dgenerate_ultralytics_headless-8.3.143.dist-info → dgenerate_ultralytics_headless-8.3.145.dist-info}/WHEEL +0 -0
- {dgenerate_ultralytics_headless-8.3.143.dist-info → dgenerate_ultralytics_headless-8.3.145.dist-info}/entry_points.txt +0 -0
- {dgenerate_ultralytics_headless-8.3.143.dist-info → dgenerate_ultralytics_headless-8.3.145.dist-info}/licenses/LICENSE +0 -0
- {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
|
-
|
21
|
-
|
22
|
-
|
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
|
-
"""
|
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
|
-
"""
|
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
|
-
"""
|
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
|
135
|
-
|
136
|
-
|
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
|
-
|
139
|
-
|
140
|
-
|
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
|
-
"""
|
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
|
-
"""
|
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
|
-
"""
|
228
|
+
def run(self, debug: bool = False):
|
229
|
+
"""Start the Flask web application server."""
|
169
230
|
self.app.run(debug=debug)
|