ultralytics 8.3.8 replace contextlib with try for speed (#16782)
Signed-off-by: UltralyticsAssistant <web@ultralytics.com> Co-authored-by: UltralyticsAssistant <web@ultralytics.com>
This commit is contained in:
parent
1e6c454460
commit
a6a577961f
12 changed files with 115 additions and 88 deletions
|
|
@ -1,6 +1,5 @@
|
|||
# Ultralytics YOLO 🚀, AGPL-3.0 license
|
||||
|
||||
import contextlib
|
||||
import glob
|
||||
import inspect
|
||||
import math
|
||||
|
|
@ -271,11 +270,13 @@ def check_latest_pypi_version(package_name="ultralytics"):
|
|||
Returns:
|
||||
(str): The latest version of the package.
|
||||
"""
|
||||
with contextlib.suppress(Exception):
|
||||
try:
|
||||
requests.packages.urllib3.disable_warnings() # Disable the InsecureRequestWarning
|
||||
response = requests.get(f"https://pypi.org/pypi/{package_name}/json", timeout=3)
|
||||
if response.status_code == 200:
|
||||
return response.json()["info"]["version"]
|
||||
except: # noqa E722
|
||||
return None
|
||||
|
||||
|
||||
def check_pip_update_available():
|
||||
|
|
@ -286,7 +287,7 @@ def check_pip_update_available():
|
|||
(bool): True if an update is available, False otherwise.
|
||||
"""
|
||||
if ONLINE and IS_PIP_PACKAGE:
|
||||
with contextlib.suppress(Exception):
|
||||
try:
|
||||
from ultralytics import __version__
|
||||
|
||||
latest = check_latest_pypi_version()
|
||||
|
|
@ -296,6 +297,8 @@ def check_pip_update_available():
|
|||
f"Update with 'pip install -U ultralytics'"
|
||||
)
|
||||
return True
|
||||
except: # noqa E722
|
||||
pass
|
||||
return False
|
||||
|
||||
|
||||
|
|
@ -577,10 +580,12 @@ def check_yolo(verbose=True, device=""):
|
|||
ram = psutil.virtual_memory().total
|
||||
total, used, free = shutil.disk_usage("/")
|
||||
s = f"({os.cpu_count()} CPUs, {ram / gib:.1f} GB RAM, {(total - free) / gib:.1f}/{total / gib:.1f} GB disk)"
|
||||
with contextlib.suppress(Exception): # clear display if ipython is installed
|
||||
try:
|
||||
from IPython import display
|
||||
|
||||
display.clear_output()
|
||||
display.clear_output() # clear display if notebook
|
||||
except ImportError:
|
||||
pass
|
||||
else:
|
||||
s = ""
|
||||
|
||||
|
|
@ -707,9 +712,10 @@ def check_amp(model):
|
|||
|
||||
def git_describe(path=ROOT): # path must be a directory
|
||||
"""Return human-readable git description, i.e. v5.0-5-g3e25f1e https://git-scm.com/docs/git-describe."""
|
||||
with contextlib.suppress(Exception):
|
||||
try:
|
||||
return subprocess.check_output(f"git -C {path} describe --tags --long --always", shell=True).decode()[:-1]
|
||||
return ""
|
||||
except: # noqa E722
|
||||
return ""
|
||||
|
||||
|
||||
def print_args(args: Optional[dict] = None, show_file=True, show_func=False):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue