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

Co-authored-by: snyk-bot <snyk-bot@snyk.io>
single_channel
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,6 +1,6 @@
# Ultralytics YOLO 🚀, AGPL-3.0 license # Ultralytics YOLO 🚀, AGPL-3.0 license
__version__ = '8.0.145' __version__ = '8.0.146'
from ultralytics.hub import start from ultralytics.hub import start
from ultralytics.models import RTDETR, SAM, YOLO 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_YAML.unlink() # delete the settings file
SETTINGS.reset() # create new settings SETTINGS.reset() # create new settings
LOGGER.info('Settings reset successfully') # inform the user that settings have been reset 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) new = dict(parse_key_value_pair(a) for a in args)
check_dict_alignment(SETTINGS, new) check_dict_alignment(SETTINGS, new)
SETTINGS.update(new) SETTINGS.update(new)

@ -714,24 +714,6 @@ def set_sentry():
logging.getLogger(logger).setLevel(logging.CRITICAL) 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): class SettingsManager(dict):
""" """
Manages Ultralytics settings stored in a YAML file. Manages Ultralytics settings stored in a YAML file.
@ -792,20 +774,15 @@ class SettingsManager(dict):
def load(self): def load(self):
"""Loads settings from the YAML file.""" """Loads settings from the YAML file."""
self.update(yaml_load(self.file)) super().update(yaml_load(self.file))
def save(self): def save(self):
"""Saves the current settings to the YAML file.""" """Saves the current settings to the YAML file."""
yaml_save(self.file, dict(self)) yaml_save(self.file, dict(self))
def update(self, *args, **kwargs): def update(self, *args, **kwargs):
"""Updates a setting value in the current settings and saves the settings.""" """Updates a setting value in the current settings."""
new = dict(*args, **kwargs) super().update(*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)
self.save() self.save()
def reset(self): def reset(self):

Loading…
Cancel
Save