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

ultralytics/__init__.py CHANGED
@@ -1,6 +1,6 @@
1
1
  # Ultralytics YOLO 🚀, AGPL-3.0 license
2
2
 
3
- __version__ = "8.2.39"
3
+ __version__ = "8.2.40"
4
4
 
5
5
  import os
6
6
 
@@ -9,7 +9,7 @@ import torch
9
9
 
10
10
  from ultralytics.cfg import TASK2DATA, get_cfg, get_save_dir
11
11
  from ultralytics.engine.results import Results
12
- from ultralytics.hub.utils import HUB_WEB_ROOT
12
+ from ultralytics.hub import HUB_WEB_ROOT, HUBTrainingSession
13
13
  from ultralytics.nn.tasks import attempt_load_one_weight, guess_model_task, nn, yaml_model_load
14
14
  from ultralytics.utils import (
15
15
  ARGV,
@@ -17,7 +17,6 @@ from ultralytics.utils import (
17
17
  DEFAULT_CFG_DICT,
18
18
  LOGGER,
19
19
  RANK,
20
- SETTINGS,
21
20
  callbacks,
22
21
  checks,
23
22
  emojis,
@@ -76,7 +75,6 @@ class Model(nn.Module):
76
75
  add_callback: Adds a callback function for an event.
77
76
  clear_callback: Clears all callbacks for an event.
78
77
  reset_callbacks: Resets all callbacks to their default functions.
79
- _get_hub_session: Retrieves or creates an Ultralytics HUB session.
80
78
  is_triton_model: Checks if a model is a Triton Server model.
81
79
  is_hub_model: Checks if a model is an Ultralytics HUB model.
82
80
  _reset_ckpt_args: Resets checkpoint arguments when loading a PyTorch model.
@@ -136,7 +134,7 @@ class Model(nn.Module):
136
134
  if self.is_hub_model(model):
137
135
  # Fetch model from HUB
138
136
  checks.check_requirements("hub-sdk>=0.0.6")
139
- self.session = self._get_hub_session(model)
137
+ self.session = HUBTrainingSession.create_session(model)
140
138
  model = self.session.model_file
141
139
 
142
140
  # Check if Triton Server model
@@ -175,14 +173,6 @@ class Model(nn.Module):
175
173
  """
176
174
  return self.predict(source, stream, **kwargs)
177
175
 
178
- @staticmethod
179
- def _get_hub_session(model: str):
180
- """Creates a session for Hub Training."""
181
- from ultralytics.hub.session import HUBTrainingSession
182
-
183
- session = HUBTrainingSession(model)
184
- return session if session.client.authenticated else None
185
-
186
176
  @staticmethod
187
177
  def is_triton_model(model: str) -> bool:
188
178
  """Is model a Triton Server URL string, i.e. <scheme>://<netloc>/<endpoint>/<task_name>"""
@@ -656,19 +646,6 @@ class Model(nn.Module):
656
646
  self.trainer.model = self.trainer.get_model(weights=self.model if self.ckpt else None, cfg=self.model.yaml)
657
647
  self.model = self.trainer.model
658
648
 
659
- if SETTINGS["hub"] is True and not self.session:
660
- # Create a model in HUB
661
- try:
662
- self.session = self._get_hub_session(self.model_name)
663
- if self.session:
664
- self.session.create_model(args)
665
- # Check model was created
666
- if not getattr(self.session.model, "id", None):
667
- self.session = None
668
- except (PermissionError, ModuleNotFoundError):
669
- # Ignore PermissionError and ModuleNotFoundError which indicates hub-sdk not installed
670
- pass
671
-
672
649
  self.trainer.hub_session = self.session # attach optional HUB session
673
650
  self.trainer.train()
674
651
  # Update model and cfg after training
@@ -4,9 +4,24 @@ import requests
4
4
 
5
5
  from ultralytics.data.utils import HUBDatasetStats
6
6
  from ultralytics.hub.auth import Auth
7
- from ultralytics.hub.utils import HUB_API_ROOT, HUB_WEB_ROOT, PREFIX
7
+ from ultralytics.hub.session import HUBTrainingSession
8
+ from ultralytics.hub.utils import HUB_API_ROOT, HUB_WEB_ROOT, PREFIX, events
8
9
  from ultralytics.utils import LOGGER, SETTINGS, checks
9
10
 
11
+ __all__ = (
12
+ "PREFIX",
13
+ "HUB_WEB_ROOT",
14
+ "HUBTrainingSession",
15
+ "login",
16
+ "logout",
17
+ "reset_model",
18
+ "export_fmts_hub",
19
+ "export_model",
20
+ "get_export",
21
+ "check_dataset",
22
+ "events",
23
+ )
24
+
10
25
 
11
26
  def login(api_key: str = None, save=True) -> bool:
12
27
  """
@@ -19,16 +19,12 @@ class HUBTrainingSession:
19
19
  HUB training session for Ultralytics HUB YOLO models. Handles model initialization, heartbeats, and checkpointing.
20
20
 
21
21
  Attributes:
22
- agent_id (str): Identifier for the instance communicating with the server.
23
22
  model_id (str): Identifier for the YOLO model being trained.
24
23
  model_url (str): URL for the model in Ultralytics HUB.
25
- api_url (str): API URL for the model in Ultralytics HUB.
26
- auth_header (dict): Authentication header for the Ultralytics HUB API requests.
27
24
  rate_limits (dict): Rate limits for different API calls (in seconds).
28
25
  timers (dict): Timers for rate limiting.
29
26
  metrics_queue (dict): Queue for the model's metrics.
30
27
  model (dict): Model data fetched from Ultralytics HUB.
31
- alive (bool): Indicates if the heartbeat loop is active.
32
28
  """
33
29
 
34
30
  def __init__(self, identifier):
@@ -46,14 +42,12 @@ class HUBTrainingSession:
46
42
  """
47
43
  from hub_sdk import HUBClient
48
44
 
49
- self.rate_limits = {
50
- "metrics": 3.0,
51
- "ckpt": 900.0,
52
- "heartbeat": 300.0,
53
- } # rate limits (seconds)
45
+ self.rate_limits = {"metrics": 3, "ckpt": 900, "heartbeat": 300} # rate limits (seconds)
54
46
  self.metrics_queue = {} # holds metrics for each epoch until upload
55
47
  self.metrics_upload_failed_queue = {} # holds metrics for each epoch if upload failed
56
48
  self.timers = {} # holds timers in ultralytics/utils/callbacks/hub.py
49
+ self.model = None
50
+ self.model_url = None
57
51
 
58
52
  # Parse input
59
53
  api_key, model_id, self.filename = self._parse_identifier(identifier)
@@ -65,10 +59,26 @@ class HUBTrainingSession:
65
59
  # Initialize client
66
60
  self.client = HUBClient(credentials)
67
61
 
68
- if model_id:
69
- self.load_model(model_id) # load existing model
70
- else:
71
- self.model = self.client.model() # load empty model
62
+ # Load models if authenticated
63
+ if self.client.authenticated:
64
+ if model_id:
65
+ self.load_model(model_id) # load existing model
66
+ else:
67
+ self.model = self.client.model() # load empty model
68
+
69
+ @classmethod
70
+ def create_session(cls, identifier, args=None):
71
+ """Class method to create an authenticated HUBTrainingSession or return None."""
72
+ try:
73
+ session = cls(identifier)
74
+ assert session.client.authenticated, "HUB not authenticated"
75
+ if args:
76
+ session.create_model(args)
77
+ assert session.model.id, "HUB model not loaded correctly"
78
+ return session
79
+ # PermissionError and ModuleNotFoundError indicate hub-sdk not installed
80
+ except (PermissionError, ModuleNotFoundError, AssertionError):
81
+ return None
72
82
 
73
83
  def load_model(self, model_id):
74
84
  """Loads an existing model from Ultralytics HUB using the provided model identifier."""
@@ -92,14 +102,12 @@ class HUBTrainingSession:
92
102
  "epochs": model_args.get("epochs", 300),
93
103
  "imageSize": model_args.get("imgsz", 640),
94
104
  "patience": model_args.get("patience", 100),
95
- "device": model_args.get("device", ""),
96
- "cache": model_args.get("cache", "ram"),
105
+ "device": str(model_args.get("device", "")), # convert None to string
106
+ "cache": str(model_args.get("cache", "ram")), # convert True, False, None to string
97
107
  },
98
108
  "dataset": {"name": model_args.get("data")},
99
109
  "lineage": {
100
- "architecture": {
101
- "name": self.filename.replace(".pt", "").replace(".yaml", ""),
102
- },
110
+ "architecture": {"name": self.filename.replace(".pt", "").replace(".yaml", "")},
103
111
  "parent": {},
104
112
  },
105
113
  "meta": {"name": self.filename},
@@ -113,7 +121,7 @@ class HUBTrainingSession:
113
121
  # Model could not be created
114
122
  # TODO: improve error handling
115
123
  if not self.model.id:
116
- return
124
+ return None
117
125
 
118
126
  self.model_url = f"{HUB_WEB_ROOT}/models/{self.model.id}"
119
127
 
@@ -122,7 +130,8 @@ class HUBTrainingSession:
122
130
 
123
131
  LOGGER.info(f"{PREFIX}View model at {self.model_url} 🚀")
124
132
 
125
- def _parse_identifier(self, identifier):
133
+ @staticmethod
134
+ def _parse_identifier(identifier):
126
135
  """
127
136
  Parses the given identifier to determine the type of identifier and extract relevant components.
128
137
 
@@ -213,13 +222,14 @@ class HUBTrainingSession:
213
222
  thread=True,
214
223
  verbose=True,
215
224
  progress_total=None,
216
- stream_reponse=None,
225
+ stream_response=None,
217
226
  *args,
218
227
  **kwargs,
219
228
  ):
220
229
  def retry_request():
221
230
  """Attempts to call `request_func` with retries, timeout, and optional threading."""
222
231
  t0 = time.time() # Record the start time for the timeout
232
+ response = None
223
233
  for i in range(retry + 1):
224
234
  if (time.time() - t0) > timeout:
225
235
  LOGGER.warning(f"{PREFIX}Timeout for request reached. {HELP_MSG}")
@@ -233,7 +243,7 @@ class HUBTrainingSession:
233
243
 
234
244
  if progress_total:
235
245
  self._show_upload_progress(progress_total, response)
236
- elif stream_reponse:
246
+ elif stream_response:
237
247
  self._iterate_content(response)
238
248
 
239
249
  if HTTPStatus.OK <= response.status_code < HTTPStatus.MULTIPLE_CHOICES:
@@ -268,7 +278,8 @@ class HUBTrainingSession:
268
278
  # If running in the main thread, call retry_request directly
269
279
  return retry_request()
270
280
 
271
- def _should_retry(self, status_code):
281
+ @staticmethod
282
+ def _should_retry(status_code):
272
283
  """Determines if a request should be retried based on the HTTP status code."""
273
284
  retry_codes = {
274
285
  HTTPStatus.REQUEST_TIMEOUT,
@@ -338,12 +349,13 @@ class HUBTrainingSession:
338
349
  timeout=3600,
339
350
  thread=not final,
340
351
  progress_total=progress_total,
341
- stream_reponse=True,
352
+ stream_response=True,
342
353
  )
343
354
  else:
344
355
  LOGGER.warning(f"{PREFIX}WARNING ⚠️ Model upload issue. Missing model {weights}.")
345
356
 
346
- def _show_upload_progress(self, content_length: int, response: requests.Response) -> None:
357
+ @staticmethod
358
+ def _show_upload_progress(content_length: int, response: requests.Response) -> None:
347
359
  """
348
360
  Display a progress bar to track the upload progress of a file download.
349
361
 
@@ -358,7 +370,8 @@ class HUBTrainingSession:
358
370
  for data in response.iter_content(chunk_size=1024):
359
371
  pbar.update(len(data))
360
372
 
361
- def _iterate_content(self, response: requests.Response) -> None:
373
+ @staticmethod
374
+ def _iterate_content(response: requests.Response) -> None:
362
375
  """
363
376
  Process the streamed HTTP response data.
364
377
 
@@ -3,8 +3,14 @@
3
3
  import json
4
4
  from time import time
5
5
 
6
- from ultralytics.hub.utils import HUB_WEB_ROOT, PREFIX, events
7
- from ultralytics.utils import LOGGER, SETTINGS
6
+ from ultralytics.hub import HUB_WEB_ROOT, PREFIX, HUBTrainingSession, events
7
+ from ultralytics.utils import LOGGER, RANK, SETTINGS
8
+
9
+
10
+ def on_pretrain_routine_start(trainer):
11
+ """Create a remote Ultralytics HUB session to log local model training."""
12
+ if RANK in {-1, 0} and SETTINGS["hub"] is True and not getattr(trainer, "hub_session", None):
13
+ trainer.hub_session = HUBTrainingSession.create_session(trainer.args.model, trainer.args)
8
14
 
9
15
 
10
16
  def on_pretrain_routine_end(trainer):
@@ -91,6 +97,7 @@ def on_export_start(exporter):
91
97
 
92
98
  callbacks = (
93
99
  {
100
+ "on_pretrain_routine_start": on_pretrain_routine_start,
94
101
  "on_pretrain_routine_end": on_pretrain_routine_end,
95
102
  "on_fit_epoch_end": on_fit_epoch_end,
96
103
  "on_model_save": on_model_save,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ultralytics
3
- Version: 8.2.39
3
+ Version: 8.2.40
4
4
  Summary: Ultralytics YOLOv8 for SOTA object detection, multi-object tracking, instance segmentation, pose estimation and image classification.
5
5
  Author: Glenn Jocher, Ayush Chaurasia, Jing Qiu
6
6
  Maintainer: Glenn Jocher, Ayush Chaurasia, Jing Qiu
@@ -7,7 +7,7 @@ tests/test_explorer.py,sha256=r1pWer2y290Y0DqsM-La7egfEY0497YCdC4rwq3URV4,2178
7
7
  tests/test_exports.py,sha256=qc4YOgsGixqYLO6IRNY16-v6z14R0dp5fdni1v222xw,8034
8
8
  tests/test_integrations.py,sha256=8Ru7GyKV8j44EEc8X9_E7q7aR4CTOIMPuSagXjSGUxw,5847
9
9
  tests/test_python.py,sha256=9KjBKQXj6T9hRfX-4nnERd7OR3xx2ejV8430BoXjHro,20536
10
- ultralytics/__init__.py,sha256=mkhFNTFZ9peN-6tReInnBdHL_JDPx-SsIZcBFTJSXW0,694
10
+ ultralytics/__init__.py,sha256=EnkTVTA0WLhbesHd-athIUXYTqm5ZUIUVcty9r4kGyE,694
11
11
  ultralytics/assets/bus.jpg,sha256=wCAZxJecGR63Od3ZRERe9Aja1Weayrb9Ug751DS_vGM,137419
12
12
  ultralytics/assets/zidane.jpg,sha256=Ftc4aeMmen1O0A3o6GCDO9FlfBslLpTAw0gnetx7bts,50427
13
13
  ultralytics/cfg/__init__.py,sha256=JblkT6Ze9MZ8hSs8gkV8JPcEKNMm-YqRqM4x501Dn9g,21507
@@ -98,15 +98,15 @@ ultralytics/data/explorer/gui/__init__.py,sha256=mHtJuK4hwF8cuV-VHDc7tp6u6D1gHz2
98
98
  ultralytics/data/explorer/gui/dash.py,sha256=CPlFIIhf53j_YVAqealsC3AbcztdPqZxfniQcBnlKK4,10042
99
99
  ultralytics/engine/__init__.py,sha256=mHtJuK4hwF8cuV-VHDc7tp6u6D1gHz2Z7JI8grmQDTs,42
100
100
  ultralytics/engine/exporter.py,sha256=RVREJjFJ7Y-pnLq_i0yM5x9QRlKoLr0WnQWepkbFD_Y,58534
101
- ultralytics/engine/model.py,sha256=wzIlzNNJUWWTb_nygVY0mK2nq3g3CyDST3lRlk-HH5M,40044
101
+ ultralytics/engine/model.py,sha256=3R-jqjW7pJX_E6cfraE20GzkQ1nngy52m3LS1uQlYtE,39046
102
102
  ultralytics/engine/predictor.py,sha256=W58kDCFH2AfoFzpGbos3k8zUEVsLunBuM8sc2B64rPY,17449
103
103
  ultralytics/engine/results.py,sha256=zRuEIrBtpoCQ3M6a_YscnyXrWSP-zpL3ACv0gTdrDaw,30987
104
104
  ultralytics/engine/trainer.py,sha256=Gkh7tFa5BlQv4pZhcAKCfKBHwR28w4AHLqALxKa8ask,35264
105
105
  ultralytics/engine/tuner.py,sha256=iZrgMmXSDpfuDu4bdFRflmAsscys2-8W8qAGxSyOVJE,11844
106
106
  ultralytics/engine/validator.py,sha256=Y21Uo8_Zto4qjk_YqQk6k7tyfpq_Qk9cfjeXeyDRxs8,14643
107
- ultralytics/hub/__init__.py,sha256=zXam81eSJ2IkH0CwPy_VhG1XHZem9vs9jR4uG7s-uAY,5383
107
+ ultralytics/hub/__init__.py,sha256=0pwI44r0JniiaCFzcwdh_vfSKlf4UTlKPGui5aOMPc8,5663
108
108
  ultralytics/hub/auth.py,sha256=FID58NE6fh7Op_B45QOpWBw1qoBN0ponL16uvyb2dZ8,5399
109
- ultralytics/hub/session.py,sha256=bIlROAp6-3kOtvMwVl7LNn_XUosGslbvgEdZiu1sYTw,15194
109
+ ultralytics/hub/session.py,sha256=l7o2RzhicROeG87_LS2Al4DWseFfEOqbaCmun8wEKlo,15733
110
110
  ultralytics/hub/utils.py,sha256=RpFDFp9biUK70Mswzz2o3uEu4xwQxRaStPS19U2gu0g,9721
111
111
  ultralytics/models/__init__.py,sha256=TT9iLCL_n9Y80dcUq0Fo-p-GRZCSU2vrWXM3CoMwqqE,265
112
112
  ultralytics/models/fastsam/__init__.py,sha256=0dt65jZ_5b7Q-mdXN8MSEkgnFRA0FIwlel_LS2RaOlU,254
@@ -213,15 +213,15 @@ ultralytics/utils/callbacks/base.py,sha256=A8H6jXnPQJfOxA1ByTBWF2ePDs5ldccUabXG0
213
213
  ultralytics/utils/callbacks/clearml.py,sha256=M9Fi1OfdWqcm8uVkauuX3zJIYhNh6Tp7Jo4CfA0u0nw,5923
214
214
  ultralytics/utils/callbacks/comet.py,sha256=QR3-9f0L_W7nZWWg_OEN7t8La2JotapSS-CnNYVjCdk,13744
215
215
  ultralytics/utils/callbacks/dvc.py,sha256=WIClMsuvhiiyrwRv5BsZLxjsxYNJ3Y8Vq7zN0Bthtro,5045
216
- ultralytics/utils/callbacks/hub.py,sha256=IPNnCRlAEFA-Dt18JWTuHhaQpcAy3XGgxBD4JhO0jSs,3586
216
+ ultralytics/utils/callbacks/hub.py,sha256=boBWcpgNUjg4b2BvxEPPgz2mldi2J_2XZv2J6h05znU,3987
217
217
  ultralytics/utils/callbacks/mlflow.py,sha256=_bUzHyPb0npne0WFlGzlGCy-X5sxGQhC_xA3dZbF08I,5391
218
218
  ultralytics/utils/callbacks/neptune.py,sha256=5Z3ua5YBTUS56FH8VQKQG1aaIo9fH8GEyzC5q7p4ipQ,3756
219
219
  ultralytics/utils/callbacks/raytune.py,sha256=ODVYzy-CoM4Uge0zjkh3Hnh9nF2M0vhDrSenXnvcizw,705
220
220
  ultralytics/utils/callbacks/tensorboard.py,sha256=QEgOVhUqY9akOs5TJIwz1Rvn6l32xWLpOxlwEyWF0B8,4136
221
221
  ultralytics/utils/callbacks/wb.py,sha256=9-fjQIdLjr3b73DTE3rHO171KvbH1VweJ-bmbv-rqTw,6747
222
- ultralytics-8.2.39.dist-info/LICENSE,sha256=DZak_2itbUtvHzD3E7GNUYSRK6jdOJ-GqncQ2weavLA,34523
223
- ultralytics-8.2.39.dist-info/METADATA,sha256=XHc9CKRpOfE9imi40-J_ziVia8M_K-JzvXbaO_ga518,41291
224
- ultralytics-8.2.39.dist-info/WHEEL,sha256=cpQTJ5IWu9CdaPViMhC9YzF8gZuS5-vlfoFihTBC86A,91
225
- ultralytics-8.2.39.dist-info/entry_points.txt,sha256=YM_wiKyTe9yRrsEfqvYolNO5ngwfoL4-NwgKzc8_7sI,93
226
- ultralytics-8.2.39.dist-info/top_level.txt,sha256=XP49TwiMw4QGsvTLSYiJhz1xF_k7ev5mQ8jJXaXi45Q,12
227
- ultralytics-8.2.39.dist-info/RECORD,,
222
+ ultralytics-8.2.40.dist-info/LICENSE,sha256=DZak_2itbUtvHzD3E7GNUYSRK6jdOJ-GqncQ2weavLA,34523
223
+ ultralytics-8.2.40.dist-info/METADATA,sha256=wH0JGdmXtJ2-3mAZZuTWXAT5WRlTPKcC-Z1XbC8erms,41291
224
+ ultralytics-8.2.40.dist-info/WHEEL,sha256=cpQTJ5IWu9CdaPViMhC9YzF8gZuS5-vlfoFihTBC86A,91
225
+ ultralytics-8.2.40.dist-info/entry_points.txt,sha256=YM_wiKyTe9yRrsEfqvYolNO5ngwfoL4-NwgKzc8_7sI,93
226
+ ultralytics-8.2.40.dist-info/top_level.txt,sha256=XP49TwiMw4QGsvTLSYiJhz1xF_k7ev5mQ8jJXaXi45Q,12
227
+ ultralytics-8.2.40.dist-info/RECORD,,