`ultralytics 8.0.146` fix SettingsManager un-needed write ops (#4101)

Co-authored-by: snyk-bot <snyk-bot@snyk.io>
pull/4381/head v8.0.146
Glenn Jocher 1 year ago committed by GitHub
parent b507e3a032
commit c3c27b019a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      ultralytics/__init__.py
  2. 2
      ultralytics/cfg/__init__.py
  3. 29
      ultralytics/utils/__init__.py

@ -1,6 +1,6 @@
# Ultralytics YOLO 🚀, AGPL-3.0 license
__version__ = '8.0.145'
__version__ = '8.0.146'
from ultralytics.hub import start
from ultralytics.models import RTDETR, SAM, YOLO

@ -253,7 +253,7 @@ def handle_yolo_settings(args: List[str]) -> None:
SETTINGS_YAML.unlink() # delete the settings file
SETTINGS.reset() # create new settings
LOGGER.info('Settings reset successfully') # inform the user that settings have been reset
else:
else: # save a new setting
new = dict(parse_key_value_pair(a) for a in args)
check_dict_alignment(SETTINGS, new)
SETTINGS.update(new)

@ -714,24 +714,6 @@ def set_sentry():
logging.getLogger(logger).setLevel(logging.CRITICAL)
def update_dict_recursive(d, u):
"""
Recursively updates the dictionary `d` with the key-value pairs from the dictionary `u` without overwriting
entire sub-dictionaries. Note that function recursion is intended and not a problem, as this allows for updating
nested dictionaries at any arbitrary depth.
Args:
d (dict): The dictionary to be updated.
u (dict): The dictionary to update `d` with.
Returns:
(dict): The recursively updated dictionary.
"""
for k, v in u.items():
d[k] = update_dict_recursive(d.get(k, {}), v) if isinstance(v, dict) else v
return d
class SettingsManager(dict):
"""
Manages Ultralytics settings stored in a YAML file.
@ -792,20 +774,15 @@ class SettingsManager(dict):
def load(self):
"""Loads settings from the YAML file."""
self.update(yaml_load(self.file))
super().update(yaml_load(self.file))
def save(self):
"""Saves the current settings to the YAML file."""
yaml_save(self.file, dict(self))
def update(self, *args, **kwargs):
"""Updates a setting value in the current settings and saves the settings."""
new = dict(*args, **kwargs)
if any(isinstance(v, dict) for v in new.values()):
update_dict_recursive(self, new)
else:
# super().update(*args, **kwargs)
super().update(new)
"""Updates a setting value in the current settings."""
super().update(*args, **kwargs)
self.save()
def reset(self):

Loading…
Cancel
Save