Skip to content

Commit

Permalink
ultralytics 8.0.86 HUB resume, Classify train and RayTune fixes (ul…
Browse files Browse the repository at this point in the history
…tralytics#2200)

Co-authored-by: Ayush Chaurasia <[email protected]>
  • Loading branch information
glenn-jocher and AyushExel authored Apr 23, 2023
1 parent 283e334 commit 3d60347
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 26 deletions.
19 changes: 9 additions & 10 deletions docs/build_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@
import re
from collections import defaultdict
from pathlib import Path
from ultralytics.yolo.utils import ROOT

TARGET_DIR = Path('..')
NEW_YAML_DIR = ROOT.parent
CODE_DIR = ROOT
REFERENCE_DIR = ROOT.parent / 'docs/reference'


def extract_classes_and_functions(filepath):
Expand All @@ -38,7 +41,7 @@ def create_markdown(py_filepath, module_path, classes, functions):
with open(md_filepath, 'w') as file:
file.write(md_content)

return md_filepath.relative_to(TARGET_DIR)
return md_filepath.relative_to(NEW_YAML_DIR)


def nested_dict():
Expand Down Expand Up @@ -77,26 +80,22 @@ def _dict_to_yaml(d, level=0):
yaml_str += f"{indent}- {k}: {str(v).replace('docs/', '')}\n"
return yaml_str

with open(TARGET_DIR / 'nav_menu_updated.yml', 'w') as file:
with open(NEW_YAML_DIR / 'nav_menu_updated.yml', 'w') as file:
yaml_str = _dict_to_yaml(nav_tree_sorted)
file.write(yaml_str)


def main():
source_dir = Path("../ultralytics")
target_dir = Path("reference")

nav_items = []

for root, _, files in os.walk(source_dir):
for root, _, files in os.walk(CODE_DIR):
for file in files:
if file.endswith(".py") and file != "__init__.py":
py_filepath = Path(root) / file
classes, functions = extract_classes_and_functions(py_filepath)

if classes or functions:
py_filepath_rel = py_filepath.relative_to(source_dir)
md_filepath = target_dir / py_filepath_rel
py_filepath_rel = py_filepath.relative_to(CODE_DIR)
md_filepath = REFERENCE_DIR / py_filepath_rel
module_path = f"ultralytics.{py_filepath_rel.with_suffix('').as_posix().replace('/', '.')}"
md_rel_filepath = create_markdown(md_filepath, module_path, classes, functions)
nav_items.append(str(md_rel_filepath))
Expand Down
4 changes: 2 additions & 2 deletions docs/reference/hub/utils.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Traces
# Events
---
:::ultralytics.hub.utils.Traces
:::ultralytics.hub.utils.Events
<br><br>

# request_with_credentials
Expand Down
1 change: 0 additions & 1 deletion docs/usage/hyperparameter_tuning.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ The following table lists the default search space parameters for hyperparameter
| warmup_momentum | `tune.uniform(0.0, 0.95)` | Warmup momentum |
| box | `tune.uniform(0.02, 0.2)` | Box loss weight |
| cls | `tune.uniform(0.2, 4.0)` | Class loss weight |
| fl_gamma | `tune.uniform(0.0, 2.0)` | Focal loss gamma |
| hsv_h | `tune.uniform(0.0, 0.1)` | Hue augmentation range |
| hsv_s | `tune.uniform(0.0, 0.9)` | Saturation augmentation range |
| hsv_v | `tune.uniform(0.0, 0.9)` | Value (brightness) augmentation range |
Expand Down
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ nav:
- comet: reference/yolo/utils/callbacks/comet.md
- hub: reference/yolo/utils/callbacks/hub.md
- mlflow: reference/yolo/utils/callbacks/mlflow.md
- neptune: reference/yolo/utils/callbacks/neptune.md
- raytune: reference/yolo/utils/callbacks/raytune.md
- tensorboard: reference/yolo/utils/callbacks/tensorboard.md
- wb: reference/yolo/utils/callbacks/wb.md
Expand Down
2 changes: 1 addition & 1 deletion ultralytics/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Ultralytics YOLO 🚀, AGPL-3.0 license

__version__ = '8.0.85'
__version__ = '8.0.86'

from ultralytics.hub import start
from ultralytics.yolo.engine.model import YOLO
Expand Down
11 changes: 7 additions & 4 deletions ultralytics/hub/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import os
import platform
import random
import sys
import threading
import time
Expand Down Expand Up @@ -147,7 +148,7 @@ class Events:
disabled when sync=False. Run 'yolo settings' to see and update settings YAML file.
Attributes:
url (str): The GA4 Measurement Protocol URL.
url (str): The URL to send anonymous events.
rate_limit (float): The rate limit in seconds for sending events.
metadata (dict): A dictionary containing metadata about the environment.
enabled (bool): A flag to enable or disable Events based on certain conditions.
Expand All @@ -165,9 +166,11 @@ def __init__(self):
self.metadata = {
'cli': Path(sys.argv[0]).name == 'yolo',
'install': 'git' if is_git_dir() else 'pip' if is_pip_package() else 'other',
'python': platform.python_version(),
'python': '.'.join(platform.python_version_tuple()[:2]), # i.e. 3.10
'version': __version__,
'env': ENVIRONMENT}
'env': ENVIRONMENT,
'session_id': round(random.random() * 1E15),
'engagement_time_msec': 1000}
self.enabled = \
SETTINGS['sync'] and \
RANK in (-1, 0) and \
Expand All @@ -180,7 +183,7 @@ def __call__(self, cfg):
Attempts to add a new event to the events list and send events if the rate limit is reached.
Args:
cfg: The configuration object containing mode and task information.
cfg (IterableSimpleNamespace): The configuration object containing mode and task information.
"""
if not self.enabled:
# Events disabled, do nothing
Expand Down
1 change: 1 addition & 0 deletions ultralytics/yolo/engine/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ def _do_train(self, world_size=1):
if self.args.close_mosaic:
base_idx = (self.epochs - self.args.close_mosaic) * nb
self.plot_idx.extend([base_idx, base_idx + 1, base_idx + 2])
epoch = self.epochs # predefine for resume fully trained model edge cases
for epoch in range(self.start_epoch, self.epochs):
self.epoch = epoch
self.run_callbacks('on_train_epoch_start')
Expand Down
36 changes: 30 additions & 6 deletions ultralytics/yolo/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -605,11 +605,35 @@ def wrapper(*args, **kwargs):

def set_sentry():
"""
Initialize the Sentry SDK for error tracking and reporting if pytest is not currently running.
Initialize the Sentry SDK for error tracking and reporting. Enabled when sync=True in settings and
disabled when sync=False. Run 'yolo settings' to see and update settings YAML file.
Conditions required to send errors:
- sync=True in YOLO settings
- pytest is not running
- running in a pip package installation
- running in a non-git directory
- running with rank -1 or 0
- online environment
- CLI used to run package (checked with 'yolo' as the name of the main CLI command)
The function also configures Sentry SDK to ignore KeyboardInterrupt and FileNotFoundError
exceptions and to exclude events with 'out of memory' in their exception message.
Additionally, the function sets custom tags and user information for Sentry events.
"""

def before_send(event, hint):
"""A function executed before sending the event to Sentry."""
"""
Modify the event before sending it to Sentry based on specific exception types and messages.
Args:
event (dict): The event dictionary containing information about the error.
hint (dict): A dictionary containing additional information about the error.
Returns:
dict: The modified event or None if the event should not be sent to Sentry.
"""
if 'exc_info' in hint:
exc_type, exc_value, tb = hint['exc_info']
if exc_type in (KeyboardInterrupt, FileNotFoundError) \
Expand All @@ -628,19 +652,19 @@ def before_send(event, hint):
Path(sys.argv[0]).name == 'yolo' and \
not TESTS_RUNNING and \
ONLINE and \
((is_pip_package() and not is_git_dir()) or
(get_git_origin_url() == 'https://github.com/ultralytics/ultralytics.git' and get_git_branch() == 'main')):
is_pip_package() and \
not is_git_dir():

import sentry_sdk # noqa
sentry_sdk.init(
dsn='https://f805855f03bb4363bc1e16cb7d87b654@o4504521589325824.ingest.sentry.io/4504521592406016',
dsn='https://5ff1556b71594bfea135ff0203a0d290@o4504521589325824.ingest.sentry.io/4504521592406016',
debug=False,
traces_sample_rate=1.0,
release=__version__,
environment='production', # 'dev' or 'production'
before_send=before_send,
ignore_errors=[KeyboardInterrupt, FileNotFoundError])
sentry_sdk.set_user({'id': SETTINGS['uuid']})
sentry_sdk.set_user({'id': SETTINGS['uuid']}) # SHA-256 anonymized UUID hash

# Disable all sentry logging
for logger in 'sentry_sdk', 'sentry_sdk.errors':
Expand Down
1 change: 0 additions & 1 deletion ultralytics/yolo/utils/tuner.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
'warmup_momentum': tune.uniform(0.0, 0.95), # warmup initial momentum
'box': tune.uniform(0.02, 0.2), # box loss gain
'cls': tune.uniform(0.2, 4.0), # cls loss gain (scale with pixels)
'fl_gamma': tune.uniform(0.0, 2.0), # focal loss gamma (efficientDet default gamma=1.5)
'hsv_h': tune.uniform(0.0, 0.1), # image HSV-Hue augmentation (fraction)
'hsv_s': tune.uniform(0.0, 0.9), # image HSV-Saturation augmentation (fraction)
'hsv_v': tune.uniform(0.0, 0.9), # image HSV-Value augmentation (fraction)
Expand Down
2 changes: 1 addition & 1 deletion ultralytics/yolo/v8/classify/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def get_model(self, cfg=None, weights=None, verbose=True):
if weights:
model.load(weights)

pretrained = False
pretrained = self.args.pretrained
for m in model.modules():
if not pretrained and hasattr(m, 'reset_parameters'):
m.reset_parameters()
Expand Down

0 comments on commit 3d60347

Please sign in to comment.