ultralytics 8.0.116 NAS, DVC, YOLOv5u updates (#3124)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Glenn Jocher
2023-06-11 20:39:32 +02:00
committed by GitHub
parent 095b856e75
commit f4e8b39fc2
12 changed files with 63 additions and 41 deletions

View File

@ -138,7 +138,7 @@ def polygon2mask(imgsz, polygons, color=1, downsample_ratio=1):
"""
Args:
imgsz (tuple): The image size.
polygons (np.ndarray): [N, M], N is the number of polygons, M is the number of points(Be divided by 2).
polygons (list[np.ndarray]): [N, M], N is the number of polygons, M is the number of points(Be divided by 2).
color (int): color
downsample_ratio (int): downsample ratio
"""

View File

@ -224,6 +224,11 @@ def set_logging(name=LOGGING_NAME, verbose=True):
'propagate': False}}})
def emojis(string=''):
"""Return platform-dependent emoji-safe version of string."""
return string.encode().decode('ascii', 'ignore') if WINDOWS else string
class EmojiFilter(logging.Filter):
"""
A custom logging filter class for removing emojis in log messages.
@ -533,6 +538,7 @@ def get_user_config_dir(sub_dir='Ultralytics'):
# GCP and AWS lambda fix, only /tmp is writeable
if not is_dir_writeable(str(path.parent)):
path = Path('/tmp') / sub_dir
LOGGER.warning(f"WARNING ⚠️ user config directory is not writeable, defaulting to '{path}'.")
# Create the subdirectory if it does not exist
path.mkdir(parents=True, exist_ok=True)
@ -544,11 +550,6 @@ USER_CONFIG_DIR = Path(os.getenv('YOLO_CONFIG_DIR', get_user_config_dir())) # U
SETTINGS_YAML = USER_CONFIG_DIR / 'settings.yaml'
def emojis(string=''):
"""Return platform-dependent emoji-safe version of string."""
return string.encode().decode('ascii', 'ignore') if WINDOWS else string
def colorstr(*input):
"""Colors a string https://en.wikipedia.org/wiki/ANSI_escape_code, i.e. colorstr('blue', 'hello world')."""
*args, string = input if len(input) > 1 else ('blue', 'bold', input[0]) # color arguments, string

View File

@ -90,7 +90,7 @@ def benchmark(model=Path(SETTINGS['weights_dir']) / 'yolov8n.pt',
filename = model.ckpt_path or model.cfg
export = model # PyTorch format
else:
filename = model.export(imgsz=imgsz, format=format, half=half, int8=int8, device=device) # all others
filename = model.export(imgsz=imgsz, format=format, half=half, int8=int8, device=device, verbose=False)
export = YOLO(filename, task=model.task)
assert suffix in str(filename), 'export failed'
emoji = '' # indicates export succeeded
@ -196,8 +196,17 @@ class ProfileModels:
model.fuse() # to report correct params and GFLOPs in model.info()
model_info = model.info()
if self.trt and self.device.type != 'cpu' and not engine_file.is_file():
engine_file = model.export(format='engine', half=True, imgsz=self.imgsz, device=self.device)
onnx_file = model.export(format='onnx', half=True, imgsz=self.imgsz, simplify=True, device=self.device)
engine_file = model.export(format='engine',
half=True,
imgsz=self.imgsz,
device=self.device,
verbose=False)
onnx_file = model.export(format='onnx',
half=True,
imgsz=self.imgsz,
simplify=True,
device=self.device,
verbose=False)
elif file.suffix == '.onnx':
model_info = self.get_onnx_model_info(file)
onnx_file = file
@ -254,7 +263,7 @@ class ProfileModels:
for _ in range(3):
start_time = time.time()
for _ in range(self.num_warmup_runs):
model(input_data, verbose=False)
model(input_data, imgsz=self.imgsz, verbose=False)
elapsed = time.time() - start_time
# Compute number of runs as higher of min_time or num_timed_runs
@ -263,7 +272,7 @@ class ProfileModels:
# Timed runs
run_times = []
for _ in tqdm(range(num_runs), desc=engine_file):
results = model(input_data, verbose=False)
results = model(input_data, imgsz=self.imgsz, verbose=False)
run_times.append(results[0].speed['inference']) # Convert to milliseconds
run_times = self.iterative_sigma_clipping(np.array(run_times), sigma=2, max_iters=3) # sigma clipping

View File

@ -42,7 +42,7 @@ def _log_images(image_path, prefix=''):
def _log_plots(plots, prefix=''):
for name, params in plots.items():
timestamp = params['timestamp']
if _processed_plots.get(name, None) != timestamp:
if _processed_plots.get(name) != timestamp:
_log_images(name, prefix)
_processed_plots[name] = timestamp

View File

@ -19,9 +19,9 @@ import requests
import torch
from matplotlib import font_manager
from ultralytics.yolo.utils import (AUTOINSTALL, LOGGER, ONLINE, ROOT, USER_CONFIG_DIR, TryExcept, clean_url, colorstr,
downloads, emojis, is_colab, is_docker, is_kaggle, is_online, is_pip_package,
url2file)
from ultralytics.yolo.utils import (AUTOINSTALL, LOGGER, ONLINE, RANK, ROOT, USER_CONFIG_DIR, TryExcept, clean_url,
colorstr, downloads, emojis, is_colab, is_docker, is_kaggle, is_online,
is_pip_package, url2file)
def is_ascii(s) -> bool:
@ -164,23 +164,26 @@ def check_font(font='Arial.ttf'):
Returns:
file (Path): Resolved font file path.
"""
name = Path(font).name
from ultralytics.yolo.utils.torch_utils import torch_distributed_zero_first
# Check USER_CONFIG_DIR
file = USER_CONFIG_DIR / name
if file.exists():
return file
with torch_distributed_zero_first(RANK):
name = Path(font).name
# Check system fonts
matches = [s for s in font_manager.findSystemFonts() if font in s]
if any(matches):
return matches[0]
# Check USER_CONFIG_DIR
file = USER_CONFIG_DIR / name
if file.exists():
return file
# Download to USER_CONFIG_DIR if missing
url = f'https://ultralytics.com/assets/{name}'
if downloads.is_url(url):
downloads.safe_download(url=url, file=file)
return file
# Check system fonts
matches = [s for s in font_manager.findSystemFonts() if font in s]
if any(matches):
return matches[0]
# Download to USER_CONFIG_DIR if missing
url = f'https://ultralytics.com/assets/{name}'
if downloads.is_url(url):
downloads.safe_download(url=url, file=file)
return file
def check_python(minimum: str = '3.7.0') -> bool: