diff --git a/hubconf.py b/hubconf.py index 86aa07b9466f..73a2b5cca60f 100644 --- a/hubconf.py +++ b/hubconf.py @@ -26,7 +26,10 @@ def _create(name, pretrained=True, channels=3, classes=80, autoshape=True, verbo Returns: YOLOv5 model """ + + import os from pathlib import Path + os.environ['YOLOv5_VERBOSE'] = str(verbose) from models.common import AutoShape, DetectMultiBackend from models.yolo import Model @@ -34,8 +37,6 @@ def _create(name, pretrained=True, channels=3, classes=80, autoshape=True, verbo from utils.general import LOGGER, check_requirements, intersect_dicts, logging from utils.torch_utils import select_device - if not verbose: - LOGGER.setLevel(logging.WARNING) check_requirements(exclude=('tensorboard', 'thop', 'opencv-python')) name = Path(name) path = name.with_suffix('.pt') if name.suffix == '' else name # checkpoint path @@ -75,9 +76,9 @@ def yolov5n(pretrained=True, channels=3, classes=80, autoshape=True, verbose=Tru return _create('yolov5n', pretrained, channels, classes, autoshape, verbose, device) -def yolov5s(pretrained=True, channels=3, classes=80, autoshape=True, verbose=True, device=None): +def yolov5s(pretrained=True, channels=3, classes=80, autoshape=True, _verbose=True, device=None): # YOLOv5-small model https://github.com/ultralytics/yolov5 - return _create('yolov5s', pretrained, channels, classes, autoshape, verbose, device) + return _create('yolov5s', pretrained, channels, classes, autoshape, _verbose, device) def yolov5m(pretrained=True, channels=3, classes=80, autoshape=True, verbose=True, device=None): diff --git a/utils/downloads.py b/utils/downloads.py index 23433cb4549f..dc5f9229c277 100644 --- a/utils/downloads.py +++ b/utils/downloads.py @@ -23,27 +23,30 @@ def gsutil_getsize(url=''): def safe_download(file, url, url2=None, min_bytes=1E0, error_msg=''): # Attempts to download file from url or url2, checks and removes incomplete downloads < min_bytes + from utils.general import LOGGER + file = Path(file) assert_msg = f"Downloaded file '{file}' does not exist or size is < min_bytes={min_bytes}" try: # url1 - print(f'Downloading {url} to {file}...') - torch.hub.download_url_to_file(url, str(file)) + LOGGER.info(f'Downloading {url} to {file}...') + torch.hub.download_url_to_file(url, str(file), progress=LOGGER.root.level <= 20) # 20=INFO logger level assert file.exists() and file.stat().st_size > min_bytes, assert_msg # check except Exception as e: # url2 file.unlink(missing_ok=True) # remove partial downloads - print(f'ERROR: {e}\nRe-attempting {url2 or url} to {file}...') + LOGGER.info(f'ERROR: {e}\nRe-attempting {url2 or url} to {file}...') os.system(f"curl -L '{url2 or url}' -o '{file}' --retry 3 -C -") # curl download, retry and resume on fail finally: if not file.exists() or file.stat().st_size < min_bytes: # check file.unlink(missing_ok=True) # remove partial downloads - print(f"ERROR: {assert_msg}\n{error_msg}") - print('') + LOGGER.info(f"ERROR: {assert_msg}\n{error_msg}") + LOGGER.info('') def attempt_download(file, repo='ultralytics/yolov5'): # from utils.downloads import *; attempt_download() # Attempt file download if does not exist - file = Path(str(file).strip().replace("'", '')) + from utils.general import LOGGER + file = Path(str(file).strip().replace("'", '')) if not file.exists(): # URL specified name = Path(urllib.parse.unquote(str(file))).name # decode '%2F' to '/' etc. @@ -51,7 +54,7 @@ def attempt_download(file, repo='ultralytics/yolov5'): # from utils.downloads i url = str(file).replace(':/', '://') # Pathlib turns :// -> :/ file = name.split('?')[0] # parse authentication https://url.com/file.txt?auth... if Path(file).is_file(): - print(f'Found {url} locally at {file}') # file already exists + LOGGER.info(f'Found {url} locally at {file}') # file already exists else: safe_download(file=file, url=url, min_bytes=1E5) return file