ultralytics-opencv-headless 8.4.10__py3-none-any.whl → 8.4.11__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.
tests/test_exports.py CHANGED
@@ -35,6 +35,10 @@ def test_export_onnx(end2end):
35
35
  def test_export_openvino(end2end):
36
36
  """Test YOLO export to OpenVINO format for model inference compatibility."""
37
37
  file = YOLO(MODEL).export(format="openvino", imgsz=32, end2end=end2end)
38
+ if WINDOWS:
39
+ # Ensure a unique export path per test to prevent OpenVINO file writes
40
+ file = Path(file)
41
+ file = file.rename(file.with_stem(f"{file.stem}-{uuid.uuid4()}"))
38
42
  YOLO(file)(SOURCE, imgsz=32) # exported model inference
39
43
 
40
44
 
@@ -66,7 +70,6 @@ def test_export_openvino_matrix(task, dynamic, int8, half, batch, nms, end2end):
66
70
  )
67
71
  if WINDOWS:
68
72
  # Use unique filenames due to Windows file permissions bug possibly due to latent threaded use
69
- # See https://github.com/ultralytics/ultralytics/actions/runs/8957949304/job/24601616830?pr=10423
70
73
  file = Path(file)
71
74
  file = file.rename(file.with_stem(f"{file.stem}-{uuid.uuid4()}"))
72
75
  YOLO(file)([SOURCE] * batch, imgsz=64 if dynamic else 32, batch=batch) # exported model inference
ultralytics/__init__.py CHANGED
@@ -1,6 +1,6 @@
1
1
  # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
2
2
 
3
- __version__ = "8.4.10"
3
+ __version__ = "8.4.11"
4
4
 
5
5
  import importlib
6
6
  import os
@@ -9,7 +9,7 @@ from concurrent.futures import ThreadPoolExecutor
9
9
  from pathlib import Path
10
10
  from time import time
11
11
 
12
- from ultralytics.utils import ENVIRONMENT, GIT, LOGGER, PYTHON_VERSION, RANK, SETTINGS, TESTS_RUNNING, colorstr
12
+ from ultralytics.utils import ENVIRONMENT, GIT, LOGGER, PYTHON_VERSION, RANK, SETTINGS, TESTS_RUNNING, Retry, colorstr
13
13
 
14
14
  PREFIX = colorstr("Platform: ")
15
15
 
@@ -148,22 +148,30 @@ def _interp_plot(plot, n=101):
148
148
  return result
149
149
 
150
150
 
151
- def _send(event, data, project, name, model_id=None):
152
- """Send event to Platform endpoint. Returns response JSON on success."""
153
- try:
154
- payload = {"event": event, "project": project, "name": name, "data": data}
155
- if model_id:
156
- payload["modelId"] = model_id
151
+ def _send(event, data, project, name, model_id=None, retry=2):
152
+ """Send event to Platform endpoint with retry logic."""
153
+ payload = {"event": event, "project": project, "name": name, "data": data}
154
+ if model_id:
155
+ payload["modelId"] = model_id
156
+
157
+ @Retry(times=retry, delay=1)
158
+ def post():
157
159
  r = requests.post(
158
160
  f"{PLATFORM_API_URL}/training/metrics",
159
161
  json=payload,
160
162
  headers={"Authorization": f"Bearer {_api_key}"},
161
- timeout=10,
163
+ timeout=30,
162
164
  )
165
+ if 400 <= r.status_code < 500 and r.status_code not in {408, 429}:
166
+ LOGGER.warning(f"{PREFIX}Failed to send {event}: {r.status_code} {r.reason}")
167
+ return None # Don't retry client errors (except 408 timeout, 429 rate limit)
163
168
  r.raise_for_status()
164
169
  return r.json()
170
+
171
+ try:
172
+ return post()
165
173
  except Exception as e:
166
- LOGGER.debug(f"Platform: Failed to send {event}: {e}")
174
+ LOGGER.debug(f"{PREFIX}Failed to send {event}: {e}")
167
175
  return None
168
176
 
169
177
 
@@ -172,40 +180,38 @@ def _send_async(event, data, project, name, model_id=None):
172
180
  _executor.submit(_send, event, data, project, name, model_id)
173
181
 
174
182
 
175
- def _upload_model(model_path, project, name):
183
+ def _upload_model(model_path, project, name, progress=False, retry=1):
176
184
  """Upload model checkpoint to Platform via signed URL."""
177
- try:
178
- model_path = Path(model_path)
179
- if not model_path.exists():
180
- return None
185
+ from ultralytics.utils.uploads import safe_upload
186
+
187
+ model_path = Path(model_path)
188
+ if not model_path.exists():
189
+ LOGGER.warning(f"{PREFIX}Model file not found: {model_path}")
190
+ return None
181
191
 
182
- # Get signed upload URL
183
- response = requests.post(
192
+ # Get signed upload URL from Platform
193
+ @Retry(times=3, delay=2)
194
+ def get_signed_url():
195
+ r = requests.post(
184
196
  f"{PLATFORM_API_URL}/models/upload",
185
197
  json={"project": project, "name": name, "filename": model_path.name},
186
198
  headers={"Authorization": f"Bearer {_api_key}"},
187
- timeout=10,
199
+ timeout=30,
188
200
  )
189
- response.raise_for_status()
190
- data = response.json()
191
-
192
- # Upload to GCS
193
- with open(model_path, "rb") as f:
194
- requests.put(
195
- data["uploadUrl"],
196
- data=f,
197
- headers={"Content-Type": "application/octet-stream"},
198
- timeout=600, # 10 min timeout for large models
199
- ).raise_for_status()
200
-
201
- # url = f"{PLATFORM_URL}/{project}/{name}"
202
- # LOGGER.info(f"{PREFIX}Model uploaded to {url}")
203
- return data.get("gcsPath")
201
+ r.raise_for_status()
202
+ return r.json()
204
203
 
204
+ try:
205
+ data = get_signed_url()
205
206
  except Exception as e:
206
- LOGGER.debug(f"Platform: Failed to upload model: {e}")
207
+ LOGGER.warning(f"{PREFIX}Failed to get upload URL: {e}")
207
208
  return None
208
209
 
210
+ # Upload to GCS using safe_upload with retry logic and optional progress bar
211
+ if safe_upload(file=model_path, url=data["uploadUrl"], retry=retry, progress=progress):
212
+ return data.get("gcsPath")
213
+ return None
214
+
209
215
 
210
216
  def _upload_model_async(model_path, project, name):
211
217
  """Upload model asynchronously using bounded thread pool."""
@@ -306,7 +312,7 @@ def on_pretrain_routine_start(trainer):
306
312
  # Note: model_info is sent later in on_fit_epoch_end (epoch 0) when the model is actually loaded
307
313
  train_args = {k: str(v) for k, v in vars(trainer.args).items()}
308
314
 
309
- # Send synchronously to get modelId for subsequent webhooks
315
+ # Send synchronously to get modelId for subsequent webhooks (critical, more retries)
310
316
  response = _send(
311
317
  "training_started",
312
318
  {
@@ -317,9 +323,12 @@ def on_pretrain_routine_start(trainer):
317
323
  },
318
324
  project,
319
325
  name,
326
+ retry=4,
320
327
  )
321
328
  if response and response.get("modelId"):
322
329
  trainer._platform_model_id = response["modelId"]
330
+ else:
331
+ LOGGER.warning(f"{PREFIX}Failed to register training session - metrics may not sync to Platform")
323
332
 
324
333
 
325
334
  def on_fit_epoch_end(trainer):
@@ -404,12 +413,14 @@ def on_train_end(trainer):
404
413
  trainer._platform_console_logger.stop_capture()
405
414
  trainer._platform_console_logger = None
406
415
 
407
- # Upload best model (blocking to ensure it completes)
408
- model_path = None
416
+ # Upload best model (blocking with progress bar to ensure it completes)
417
+ gcs_path = None
409
418
  model_size = None
410
419
  if trainer.best and Path(trainer.best).exists():
411
420
  model_size = Path(trainer.best).stat().st_size
412
- model_path = _upload_model(trainer.best, project, name)
421
+ gcs_path = _upload_model(trainer.best, project, name, progress=True, retry=3)
422
+ if not gcs_path:
423
+ LOGGER.warning(f"{PREFIX}Model will not be available for download on Platform (upload failed)")
413
424
 
414
425
  # Collect plots from trainer and validator, deduplicating by type
415
426
  plots_by_type = {}
@@ -432,7 +443,7 @@ def on_train_end(trainer):
432
443
  "metrics": {**trainer.metrics, "fitness": trainer.fitness},
433
444
  "bestEpoch": getattr(trainer, "best_epoch", trainer.epoch),
434
445
  "bestFitness": trainer.best_fitness,
435
- "modelPath": model_path or (str(trainer.best) if trainer.best else None),
446
+ "modelPath": gcs_path, # Only send GCS path, not local path
436
447
  "modelSize": model_size,
437
448
  },
438
449
  "classNames": class_names,
@@ -441,6 +452,7 @@ def on_train_end(trainer):
441
452
  project,
442
453
  name,
443
454
  getattr(trainer, "_platform_model_id", None),
455
+ retry=4, # Critical, more retries
444
456
  )
445
457
  url = f"{PLATFORM_URL}/{project}/{name}"
446
458
  LOGGER.info(f"{PREFIX}View results at {url}")
@@ -0,0 +1,115 @@
1
+ # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
2
+ """Upload utilities for Ultralytics, mirroring downloads.py patterns."""
3
+
4
+ from __future__ import annotations
5
+
6
+ import os
7
+ from pathlib import Path
8
+ from time import sleep
9
+
10
+ from ultralytics.utils import LOGGER, TQDM
11
+
12
+
13
+ class _ProgressReader:
14
+ """File wrapper that reports read progress for upload monitoring."""
15
+
16
+ def __init__(self, file_path, pbar):
17
+ self.file = open(file_path, "rb")
18
+ self.pbar = pbar
19
+ self._size = os.path.getsize(file_path)
20
+
21
+ def read(self, size=-1):
22
+ """Read data and update progress bar."""
23
+ data = self.file.read(size)
24
+ if data and self.pbar:
25
+ self.pbar.update(len(data))
26
+ return data
27
+
28
+ def __len__(self):
29
+ """Return file size for Content-Length header."""
30
+ return self._size
31
+
32
+ def close(self):
33
+ """Close the file."""
34
+ self.file.close()
35
+
36
+
37
+ def safe_upload(
38
+ file: str | Path,
39
+ url: str,
40
+ headers: dict | None = None,
41
+ retry: int = 2,
42
+ timeout: int = 600,
43
+ progress: bool = False,
44
+ ) -> bool:
45
+ """Upload a file to a URL with retry logic and optional progress bar.
46
+
47
+ Args:
48
+ file (str | Path): Path to the file to upload.
49
+ url (str): The URL endpoint to upload the file to (e.g., signed GCS URL).
50
+ headers (dict, optional): Additional headers to include in the request.
51
+ retry (int, optional): Number of retry attempts on failure (default: 2 for 3 total attempts).
52
+ timeout (int, optional): Request timeout in seconds.
53
+ progress (bool, optional): Whether to display a progress bar during upload.
54
+
55
+ Returns:
56
+ (bool): True if upload succeeded, False otherwise.
57
+
58
+ Examples:
59
+ >>> from ultralytics.utils.uploads import safe_upload
60
+ >>> success = safe_upload("model.pt", "https://storage.googleapis.com/...", progress=True)
61
+ """
62
+ import requests
63
+
64
+ file = Path(file)
65
+ if not file.exists():
66
+ raise FileNotFoundError(f"File not found: {file}")
67
+
68
+ file_size = file.stat().st_size
69
+ desc = f"Uploading {file.name}"
70
+
71
+ # Prepare headers (Content-Length set automatically from file size)
72
+ upload_headers = {"Content-Type": "application/octet-stream"}
73
+ if headers:
74
+ upload_headers.update(headers)
75
+
76
+ last_error = None
77
+ for attempt in range(retry + 1):
78
+ pbar = None
79
+ reader = None
80
+ try:
81
+ if progress:
82
+ pbar = TQDM(total=file_size, desc=desc, unit="B", unit_scale=True, unit_divisor=1024)
83
+ reader = _ProgressReader(file, pbar)
84
+
85
+ r = requests.put(url, data=reader, headers=upload_headers, timeout=timeout)
86
+ r.raise_for_status()
87
+ reader.close()
88
+ reader = None # Prevent double-close in finally
89
+ if pbar:
90
+ pbar.close()
91
+ pbar = None
92
+ LOGGER.info(f"Uploaded {file.name} ✅")
93
+ return True
94
+
95
+ except requests.exceptions.HTTPError as e:
96
+ status = e.response.status_code if e.response is not None else 0
97
+ if 400 <= status < 500 and status not in {408, 429}:
98
+ LOGGER.warning(f"{desc} failed: {status} {getattr(e.response, 'reason', '')}")
99
+ return False
100
+ last_error = f"HTTP {status}"
101
+ except Exception as e:
102
+ last_error = str(e)
103
+ finally:
104
+ if reader:
105
+ reader.close()
106
+ if pbar:
107
+ pbar.close()
108
+
109
+ if attempt < retry:
110
+ wait_time = 2 ** (attempt + 1)
111
+ LOGGER.warning(f"{desc} failed ({last_error}), retrying {attempt + 1}/{retry} in {wait_time}s...")
112
+ sleep(wait_time)
113
+
114
+ LOGGER.warning(f"{desc} failed after {retry + 1} attempts: {last_error}")
115
+ return False
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ultralytics-opencv-headless
3
- Version: 8.4.10
3
+ Version: 8.4.11
4
4
  Summary: Ultralytics YOLO 🚀 for SOTA object detection, multi-object tracking, instance segmentation, pose estimation and image classification.
5
5
  Author-email: Glenn Jocher <glenn.jocher@ultralytics.com>, Jing Qiu <jing.qiu@ultralytics.com>
6
6
  Maintainer-email: Ultralytics <hello@ultralytics.com>
@@ -3,11 +3,11 @@ tests/conftest.py,sha256=rlKyDuOC_3ptXrWS8Q19bNEGOupUmYXHj3nB6o1GBGY,2318
3
3
  tests/test_cli.py,sha256=-OrAcZlcJ07UPagjSOlR8qXP5gNFHaTYcW3paOTURAE,5725
4
4
  tests/test_cuda.py,sha256=1CSODefiLsbkYUJ34Bdg5c6w50WNoqdoLBuXxWP0Ewo,8477
5
5
  tests/test_engine.py,sha256=ufSn3X4kL_Lpn2O25jKAfw_9QwHTMRjP9shDdpgBqnY,5740
6
- tests/test_exports.py,sha256=pZZJBN2uM5QdQMjnjIC-xZkKPOBbnnX8b5d5q90otl4,15651
6
+ tests/test_exports.py,sha256=NaVQVjBG2zRNCfZqwtZtLar-poEC_TZe6AgGdMjEdy8,15740
7
7
  tests/test_integrations.py,sha256=FjvTGjXm3bvYHK3_obgObhC5SzHCTzw4aOJV9Hh08jQ,6220
8
8
  tests/test_python.py,sha256=amdS9eDhjpiN0aVc5d8awxaTYjIZUlfV909ykhhD7W8,30730
9
9
  tests/test_solutions.py,sha256=1tRlM72YciE42Nk9v83gsXOD5RSx9GSWVsKGhH7-HxE,14122
10
- ultralytics/__init__.py,sha256=FtbFMrML8PlTVGpQeRFnqV_TMA_yiVxOuXp7vH766ng,1301
10
+ ultralytics/__init__.py,sha256=Q9kssdso3ZnpR4RchX5mVYX0Xz3X75oyRNPlLMIbfz8,1301
11
11
  ultralytics/py.typed,sha256=la67KBlbjXN-_-DfGNcdOcjYumVpKG_Tkw-8n5dnGB4,8
12
12
  ultralytics/assets/bus.jpg,sha256=wCAZxJecGR63Od3ZRERe9Aja1Weayrb9Ug751DS_vGM,137419
13
13
  ultralytics/assets/zidane.jpg,sha256=Ftc4aeMmen1O0A3o6GCDO9FlfBslLpTAw0gnetx7bts,50427
@@ -287,6 +287,7 @@ ultralytics/utils/torch_utils.py,sha256=H0ykzePdr55qPndFS9VVQCFH-fovbpK_uVBz4ooL
287
287
  ultralytics/utils/tqdm.py,sha256=f2W608Qpvgu6tFi28qylaZpcRv3IX8wTGY_8lgicaqY,16343
288
288
  ultralytics/utils/triton.py,sha256=BQu3CD3OlT76d1OtmnX5slQU37VC1kzRvEtfI2saIQA,5211
289
289
  ultralytics/utils/tuner.py,sha256=nRMmnyp0B0gVJzAXcpCxQUnwXjVp0WNiSJwxyR2xvQM,7303
290
+ ultralytics/utils/uploads.py,sha256=wLIIdzQmJYk3yyV-JC3GP2hxuEZ_ypNZeuh59QZuc7o,3809
290
291
  ultralytics/utils/callbacks/__init__.py,sha256=hzL63Rce6VkZhP4Lcim9LKjadixaQG86nKqPhk7IkS0,242
291
292
  ultralytics/utils/callbacks/base.py,sha256=floD31JHqHpiVabQiE76_hzC_j7KjtL4w_czkD1bLKc,6883
292
293
  ultralytics/utils/callbacks/clearml.py,sha256=LjfNe4mswceCOpEGVLxqGXjkl_XGbef4awdcp4502RU,5831
@@ -295,7 +296,7 @@ ultralytics/utils/callbacks/dvc.py,sha256=YT0Sa5P8Huj8Fn9jM2P6MYzUY3PIVxsa5BInVi
295
296
  ultralytics/utils/callbacks/hub.py,sha256=fVLqqr3ZM6hoYFlVMEeejfq1MWDrkWCskPFOG3HGILQ,4159
296
297
  ultralytics/utils/callbacks/mlflow.py,sha256=wCXjQgdufp9LYujqMzLZOmIOur6kvrApHNeo9dA7t_g,5323
297
298
  ultralytics/utils/callbacks/neptune.py,sha256=_vt3cMwDHCR-LyT3KtRikGpj6AG11oQ-skUUUUdZ74o,4391
298
- ultralytics/utils/callbacks/platform.py,sha256=Utc9X3SDEGcvyQLaujQs3IA8UpFvmJcQC6HmLnTV4XA,16202
299
+ ultralytics/utils/callbacks/platform.py,sha256=uEjJSLJ89mYYXJq4zaikCsjTHKHAmZRq4YdxjQh-ywE,16851
299
300
  ultralytics/utils/callbacks/raytune.py,sha256=Y0dFyNZVRuFovSh7nkgUIHTQL3xIXOACElgHuYbg_5I,1278
300
301
  ultralytics/utils/callbacks/tensorboard.py,sha256=K7b6KtC7rimfzqFu-NDZ_55Tbd7eC6TckqQdTNPuQ6U,5039
301
302
  ultralytics/utils/callbacks/wb.py,sha256=ci6lYVRneKTRC5CL6FRf9_iOYznwU74p9_fV3s9AbfQ,7907
@@ -303,9 +304,9 @@ ultralytics/utils/export/__init__.py,sha256=Cfh-PwVfTF_lwPp-Ss4wiX4z8Sm1XRPklsqd
303
304
  ultralytics/utils/export/engine.py,sha256=QoXPqnmQn6W5TOUAygOtCG63R9ExDG4-Df6X6W-_Mzo,10470
304
305
  ultralytics/utils/export/imx.py,sha256=VnMDO7c8ezBs91UDoLg9rR0oY8Uc7FujKpbdGxrzV18,13744
305
306
  ultralytics/utils/export/tensorflow.py,sha256=xHEcEM3_VeYctyqkJCpgkqcNie1M8xLqcFKr6uANEEQ,9951
306
- ultralytics_opencv_headless-8.4.10.dist-info/licenses/LICENSE,sha256=DZak_2itbUtvHzD3E7GNUYSRK6jdOJ-GqncQ2weavLA,34523
307
- ultralytics_opencv_headless-8.4.10.dist-info/METADATA,sha256=PHkk8v4-VHj9saUGpEMI700rLqTcq9z37unLYsL_Vsc,38999
308
- ultralytics_opencv_headless-8.4.10.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
309
- ultralytics_opencv_headless-8.4.10.dist-info/entry_points.txt,sha256=YM_wiKyTe9yRrsEfqvYolNO5ngwfoL4-NwgKzc8_7sI,93
310
- ultralytics_opencv_headless-8.4.10.dist-info/top_level.txt,sha256=XP49TwiMw4QGsvTLSYiJhz1xF_k7ev5mQ8jJXaXi45Q,12
311
- ultralytics_opencv_headless-8.4.10.dist-info/RECORD,,
307
+ ultralytics_opencv_headless-8.4.11.dist-info/licenses/LICENSE,sha256=DZak_2itbUtvHzD3E7GNUYSRK6jdOJ-GqncQ2weavLA,34523
308
+ ultralytics_opencv_headless-8.4.11.dist-info/METADATA,sha256=JAur8AWBUPnnGsdfagIh6SGMLM9hHMK5TMDqAxlAXcs,38999
309
+ ultralytics_opencv_headless-8.4.11.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
310
+ ultralytics_opencv_headless-8.4.11.dist-info/entry_points.txt,sha256=YM_wiKyTe9yRrsEfqvYolNO5ngwfoL4-NwgKzc8_7sI,93
311
+ ultralytics_opencv_headless-8.4.11.dist-info/top_level.txt,sha256=XP49TwiMw4QGsvTLSYiJhz1xF_k7ev5mQ8jJXaXi45Q,12
312
+ ultralytics_opencv_headless-8.4.11.dist-info/RECORD,,