ultralytics 8.0.75 fixes and updates (#1967)
Co-authored-by: Laughing-q <1185102784@qq.com> Co-authored-by: Jonathan Rayner <jonathan.j.rayner@gmail.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
e5cb35edfc
commit
48c4483795
9 changed files with 128 additions and 98 deletions
|
|
@ -17,6 +17,7 @@ from types import SimpleNamespace
|
|||
from typing import Union
|
||||
|
||||
import cv2
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
import torch
|
||||
import yaml
|
||||
|
|
@ -116,7 +117,7 @@ class SimpleClass:
|
|||
attr = []
|
||||
for a in dir(self):
|
||||
v = getattr(self, a)
|
||||
if not callable(v) and not a.startswith('__'):
|
||||
if not callable(v) and not a.startswith('_'):
|
||||
if isinstance(v, SimpleClass):
|
||||
# Display only the module and class name for subclasses
|
||||
s = f'{a}: {v.__module__}.{v.__class__.__name__} object'
|
||||
|
|
@ -164,6 +165,39 @@ class IterableSimpleNamespace(SimpleNamespace):
|
|||
return getattr(self, key, default)
|
||||
|
||||
|
||||
def plt_settings(rcparams={'font.size': 11}, backend='Agg'):
|
||||
"""
|
||||
Decorator to temporarily set rc parameters and the backend for a plotting function.
|
||||
|
||||
Usage:
|
||||
decorator: @plt_settings({"font.size": 12})
|
||||
context manager: with plt_settings({"font.size": 12}):
|
||||
|
||||
Args:
|
||||
rcparams (dict): Dictionary of rc parameters to set.
|
||||
backend (str, optional): Name of the backend to use. Defaults to 'Agg'.
|
||||
|
||||
Returns:
|
||||
callable: Decorated function with temporarily set rc parameters and backend.
|
||||
"""
|
||||
|
||||
def decorator(func):
|
||||
|
||||
def wrapper(*args, **kwargs):
|
||||
original_backend = plt.get_backend()
|
||||
plt.switch_backend(backend)
|
||||
|
||||
with plt.rc_context(rcparams):
|
||||
result = func(*args, **kwargs)
|
||||
|
||||
plt.switch_backend(original_backend)
|
||||
return result
|
||||
|
||||
return wrapper
|
||||
|
||||
return decorator
|
||||
|
||||
|
||||
def set_logging(name=LOGGING_NAME, verbose=True):
|
||||
# sets up logging for the given name
|
||||
rank = int(os.getenv('RANK', -1)) # rank in world for Multi-GPU trainings
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue