Improve check_imshow() robustness (#4483)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Glenn Jocher 2023-08-21 23:41:11 +02:00 committed by GitHub
parent c0a9660310
commit 1cec0185a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 7 deletions

View File

@ -311,14 +311,15 @@ def test_utils_init():
def test_utils_checks(): def test_utils_checks():
from ultralytics.utils.checks import (check_imgsz, check_requirements, check_yolov5u_filename, git_describe, from ultralytics.utils.checks import (check_imgsz, check_imshow, check_requirements, check_yolov5u_filename,
print_args) git_describe, print_args)
check_yolov5u_filename('yolov5n.pt') check_yolov5u_filename('yolov5n.pt')
# check_imshow(warn=True) # check_imshow(warn=True)
git_describe(ROOT) git_describe(ROOT)
check_requirements() # check requirements.txt check_requirements() # check requirements.txt
check_imgsz([600, 600], max_dim=1) check_imgsz([600, 600], max_dim=1)
check_imshow()
print_args() print_args()

View File

@ -20,9 +20,9 @@ import requests
import torch import torch
from matplotlib import font_manager from matplotlib import font_manager
from ultralytics.utils import (ASSETS, AUTOINSTALL, LOGGER, ONLINE, ROOT, USER_CONFIG_DIR, ThreadingLocked, TryExcept, from ultralytics.utils import (ASSETS, AUTOINSTALL, LINUX, LOGGER, ONLINE, ROOT, USER_CONFIG_DIR, ThreadingLocked,
clean_url, colorstr, downloads, emojis, is_colab, is_docker, is_jupyter, is_kaggle, TryExcept, clean_url, colorstr, downloads, emojis, is_colab, is_docker, is_jupyter,
is_online, is_pip_package, url2file) is_kaggle, is_online, is_pip_package, url2file)
def is_ascii(s) -> bool: def is_ascii(s) -> bool:
@ -389,8 +389,9 @@ def check_yaml(file, suffix=('.yaml', '.yml'), hard=True):
def check_imshow(warn=False): def check_imshow(warn=False):
"""Check if environment supports image displays.""" """Check if environment supports image displays."""
try: try:
assert not any((is_colab(), is_kaggle(), is_docker())) if LINUX:
cv2.imshow('test', np.zeros((1, 1, 3))) assert 'DISPLAY' in os.environ and not is_docker() and not is_colab() and not is_kaggle()
cv2.imshow('test', np.zeros((8, 8, 3), dtype=np.uint8)) # show a small 8-pixel image
cv2.waitKey(1) cv2.waitKey(1)
cv2.destroyAllWindows() cv2.destroyAllWindows()
cv2.waitKey(1) cv2.waitKey(1)