From 10bf93e32fe7d46cd6abce261a97b81570d2ee17 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Mon, 17 Oct 2022 13:00:27 +0200 Subject: [PATCH 01/17] Allow PyTorch Hub results to display in notebooks --- classify/predict.py | 2 +- detect.py | 2 +- models/common.py | 11 +++++++---- segment/predict.py | 2 +- utils/general.py | 7 ++++--- 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/classify/predict.py b/classify/predict.py index 9114aab1d703..9373649bf27d 100644 --- a/classify/predict.py +++ b/classify/predict.py @@ -91,7 +91,7 @@ def run( # Dataloader bs = 1 # batch_size if webcam: - view_img = check_imshow() + view_img = check_imshow(warn=True) dataset = LoadStreams(source, img_size=imgsz, transforms=classify_transforms(imgsz[0]), vid_stride=vid_stride) bs = len(dataset) elif screenshot: diff --git a/detect.py b/detect.py index 8f48d8d28000..98af7235ea69 100644 --- a/detect.py +++ b/detect.py @@ -99,7 +99,7 @@ def run( # Dataloader bs = 1 # batch_size if webcam: - view_img = check_imshow() + view_img = check_imshow(warn=True) dataset = LoadStreams(source, img_size=imgsz, stride=stride, auto=pt, vid_stride=vid_stride) bs = len(dataset) elif screenshot: diff --git a/models/common.py b/models/common.py index d889d0292c61..a84b75b19e8c 100644 --- a/models/common.py +++ b/models/common.py @@ -18,16 +18,19 @@ import requests import torch import torch.nn as nn +from IPython.display import display from PIL import Image from torch.cuda import amp from utils.dataloaders import exif_transpose, letterbox -from utils.general import (LOGGER, ROOT, Profile, check_requirements, check_suffix, check_version, colorstr, - increment_path, make_divisible, non_max_suppression, scale_boxes, xywh2xyxy, xyxy2xywh, - yaml_load) +from utils.general import (LOGGER, ROOT, Profile, check_imshow, check_requirements, check_suffix, check_version, + colorstr, increment_path, make_divisible, non_max_suppression, scale_boxes, xywh2xyxy, + xyxy2xywh, yaml_load) from utils.plots import Annotator, colors, save_one_box from utils.torch_utils import copy_attr, smart_inference_mode +IMSHOW_SUPPORT = check_imshow() + def autopad(k, p=None, d=1): # kernel, padding, dilation # Pad to 'same' shape outputs @@ -756,7 +759,7 @@ def _run(self, pprint=False, show=False, save=False, crop=False, render=False, l im = Image.fromarray(im.astype(np.uint8)) if isinstance(im, np.ndarray) else im # from np if show: - im.show(self.files[i]) # show + im.show(self.files[i]) if IMSHOW_SUPPORT else display(im) if save: f = self.files[i] im.save(save_dir / f) # save diff --git a/segment/predict.py b/segment/predict.py index 94117cd78633..44d6d3904c19 100644 --- a/segment/predict.py +++ b/segment/predict.py @@ -102,7 +102,7 @@ def run( # Dataloader bs = 1 # batch_size if webcam: - view_img = check_imshow() + view_img = check_imshow(warn=True) dataset = LoadStreams(source, img_size=imgsz, stride=stride, auto=pt, vid_stride=vid_stride) bs = len(dataset) elif screenshot: diff --git a/utils/general.py b/utils/general.py index d9d54d9e4f71..f1ebeb9cd8e8 100644 --- a/utils/general.py +++ b/utils/general.py @@ -383,18 +383,19 @@ def check_img_size(imgsz, s=32, floor=0): return new_size -def check_imshow(): +def check_imshow(warn=False): # Check if environment supports image displays try: - assert not is_docker(), 'cv2.imshow() is disabled in Docker environments' assert not is_colab(), 'cv2.imshow() is disabled in Google Colab environments' + assert not is_docker(), 'cv2.imshow() is disabled in Docker environments' cv2.imshow('test', np.zeros((1, 1, 3))) cv2.waitKey(1) cv2.destroyAllWindows() cv2.waitKey(1) return True except Exception as e: - LOGGER.warning(f'WARNING ⚠️ Environment does not support cv2.imshow() or PIL Image.show() image displays\n{e}') + if warn: + LOGGER.warning(f'WARNING ⚠️ Environment does not support cv2.imshow() or PIL Image.show()\n{e}') return False From e1de2705d120ae9f4d6c33a6da63489af0b6dccf Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Mon, 17 Oct 2022 13:07:38 +0200 Subject: [PATCH 02/17] fix CI --- models/common.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/models/common.py b/models/common.py index a84b75b19e8c..d70549fa0c43 100644 --- a/models/common.py +++ b/models/common.py @@ -18,10 +18,10 @@ import requests import torch import torch.nn as nn -from IPython.display import display from PIL import Image from torch.cuda import amp +from utils import TryExcept from utils.dataloaders import exif_transpose, letterbox from utils.general import (LOGGER, ROOT, Profile, check_imshow, check_requirements, check_suffix, check_version, colorstr, increment_path, make_divisible, non_max_suppression, scale_boxes, xywh2xyxy, @@ -759,7 +759,11 @@ def _run(self, pprint=False, show=False, save=False, crop=False, render=False, l im = Image.fromarray(im.astype(np.uint8)) if isinstance(im, np.ndarray) else im # from np if show: - im.show(self.files[i]) if IMSHOW_SUPPORT else display(im) + if IMSHOW_SUPPORT: + im.show(self.files[i]) + else: + from IPython.display import display + display(im) if save: f = self.files[i] im.save(save_dir / f) # save @@ -775,6 +779,7 @@ def _run(self, pprint=False, show=False, save=False, crop=False, render=False, l LOGGER.info(f'Saved results to {save_dir}\n') return crops + @TryExcept('Showing images is not supported in this environment') def show(self, labels=True): self._run(show=True, labels=labels) # show results From cc1c54585e5f0e9ab3a97550e9569fc483594320 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Mon, 17 Oct 2022 13:35:19 +0200 Subject: [PATCH 03/17] fix CI --- utils/general.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/utils/general.py b/utils/general.py index f1ebeb9cd8e8..44fde65dfaef 100644 --- a/utils/general.py +++ b/utils/general.py @@ -33,6 +33,7 @@ import torch import torchvision import yaml +import IPython from utils import TryExcept, emojis from utils.downloads import gsutil_getsize @@ -73,6 +74,12 @@ def is_colab(): return 'COLAB_GPU' in os.environ +def is_notebook(): + # Is environment a Jupyter notebook? Verified on Colab, Jupyterlab, Kaggle, Paperspace + ipython_type = str(type(IPython.get_ipython())) + return 'colab' in ipython_type or 'zmqshell' in ipython_type + + def is_kaggle(): # Is environment a Kaggle Notebook? return os.environ.get('PWD') == '/kaggle/working' and os.environ.get('KAGGLE_URL_BASE') == 'https://www.kaggle.com' @@ -386,8 +393,8 @@ def check_img_size(imgsz, s=32, floor=0): def check_imshow(warn=False): # Check if environment supports image displays try: - assert not is_colab(), 'cv2.imshow() is disabled in Google Colab environments' - assert not is_docker(), 'cv2.imshow() is disabled in Docker environments' + assert not is_notebook(), 'cv2.imshow() is disabled in Jupyter notebooks' + assert not is_docker(), 'cv2.imshow() is disabled in Docker containers' cv2.imshow('test', np.zeros((1, 1, 3))) cv2.waitKey(1) cv2.destroyAllWindows() From 64a95e24da0861cb18a2fcabee8a1f0e19928a9f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 17 Oct 2022 11:35:54 +0000 Subject: [PATCH 04/17] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- utils/general.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/general.py b/utils/general.py index 44fde65dfaef..47b721fc0d69 100644 --- a/utils/general.py +++ b/utils/general.py @@ -27,13 +27,13 @@ from zipfile import ZipFile import cv2 +import IPython import numpy as np import pandas as pd import pkg_resources as pkg import torch import torchvision import yaml -import IPython from utils import TryExcept, emojis from utils.downloads import gsutil_getsize From 8c0a6ae4ac831ecdca40f32c94db622603e73877 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Mon, 17 Oct 2022 13:39:51 +0200 Subject: [PATCH 05/17] fix CI --- utils/general.py | 1 + 1 file changed, 1 insertion(+) diff --git a/utils/general.py b/utils/general.py index 44fde65dfaef..8e79662f0d6b 100644 --- a/utils/general.py +++ b/utils/general.py @@ -77,6 +77,7 @@ def is_colab(): def is_notebook(): # Is environment a Jupyter notebook? Verified on Colab, Jupyterlab, Kaggle, Paperspace ipython_type = str(type(IPython.get_ipython())) + print(f'IPYTHON_TYPE: {ipython_type}') return 'colab' in ipython_type or 'zmqshell' in ipython_type From 7a1d49b22d83441a93f327b3397b0b63a1ae360f Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Mon, 17 Oct 2022 13:42:24 +0200 Subject: [PATCH 06/17] fix CI --- utils/general.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/utils/general.py b/utils/general.py index ab7ee511d5ff..4a54756405c7 100644 --- a/utils/general.py +++ b/utils/general.py @@ -57,6 +57,8 @@ os.environ['NUMEXPR_MAX_THREADS'] = str(NUM_THREADS) # NumExpr max threads os.environ['OMP_NUM_THREADS'] = '1' if platform.system() == 'darwin' else str(NUM_THREADS) # OpenMP (PyTorch and SciPy) +ipython_type = str(type(IPython.get_ipython())) +print(f'IPYTHON_TYPE: {ipython_type}') def is_ascii(s=''): # Is string composed of all ASCII (no UTF) characters? (note str().isascii() introduced in python 3.7) @@ -77,7 +79,6 @@ def is_colab(): def is_notebook(): # Is environment a Jupyter notebook? Verified on Colab, Jupyterlab, Kaggle, Paperspace ipython_type = str(type(IPython.get_ipython())) - print(f'IPYTHON_TYPE: {ipython_type}') return 'colab' in ipython_type or 'zmqshell' in ipython_type From ba2c668e492d747f25f94e66a41e1f77f815ce5e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 17 Oct 2022 11:43:23 +0000 Subject: [PATCH 07/17] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- utils/general.py | 1 + 1 file changed, 1 insertion(+) diff --git a/utils/general.py b/utils/general.py index 4a54756405c7..316d5f52fa52 100644 --- a/utils/general.py +++ b/utils/general.py @@ -60,6 +60,7 @@ ipython_type = str(type(IPython.get_ipython())) print(f'IPYTHON_TYPE: {ipython_type}') + def is_ascii(s=''): # Is string composed of all ASCII (no UTF) characters? (note str().isascii() introduced in python 3.7) s = str(s) # convert list, tuple, None, etc. to str From 17a268912deda131d5e1c392bf4c62a3e8f442c1 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Mon, 17 Oct 2022 13:46:40 +0200 Subject: [PATCH 08/17] fix CI --- .github/workflows/ci-testing.yml | 2 ++ utils/general.py | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci-testing.yml b/.github/workflows/ci-testing.yml index 1ec68e8412f9..0ec5f5069332 100644 --- a/.github/workflows/ci-testing.yml +++ b/.github/workflows/ci-testing.yml @@ -110,6 +110,8 @@ jobs: python --version pip --version pip list + + python -c "print(str(type(IPython.get_ipython())))" - name: Test detection shell: bash # for Windows compatibility run: | diff --git a/utils/general.py b/utils/general.py index 4a54756405c7..47b721fc0d69 100644 --- a/utils/general.py +++ b/utils/general.py @@ -57,8 +57,6 @@ os.environ['NUMEXPR_MAX_THREADS'] = str(NUM_THREADS) # NumExpr max threads os.environ['OMP_NUM_THREADS'] = '1' if platform.system() == 'darwin' else str(NUM_THREADS) # OpenMP (PyTorch and SciPy) -ipython_type = str(type(IPython.get_ipython())) -print(f'IPYTHON_TYPE: {ipython_type}') def is_ascii(s=''): # Is string composed of all ASCII (no UTF) characters? (note str().isascii() introduced in python 3.7) From ce836af29f31d1a87549cde191bde44f409e7cd9 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 17 Oct 2022 11:47:38 +0000 Subject: [PATCH 09/17] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .github/workflows/ci-testing.yml | 2 +- utils/general.py | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/ci-testing.yml b/.github/workflows/ci-testing.yml index 0ec5f5069332..d9c5cdfed9f3 100644 --- a/.github/workflows/ci-testing.yml +++ b/.github/workflows/ci-testing.yml @@ -110,7 +110,7 @@ jobs: python --version pip --version pip list - + python -c "print(str(type(IPython.get_ipython())))" - name: Test detection shell: bash # for Windows compatibility diff --git a/utils/general.py b/utils/general.py index cffe27ea14a2..47b721fc0d69 100644 --- a/utils/general.py +++ b/utils/general.py @@ -58,7 +58,6 @@ os.environ['OMP_NUM_THREADS'] = '1' if platform.system() == 'darwin' else str(NUM_THREADS) # OpenMP (PyTorch and SciPy) - def is_ascii(s=''): # Is string composed of all ASCII (no UTF) characters? (note str().isascii() introduced in python 3.7) s = str(s) # convert list, tuple, None, etc. to str From 41ee9882f42934bc24a0329a0f4d64af4cb78801 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Mon, 17 Oct 2022 13:51:13 +0200 Subject: [PATCH 10/17] fix CI --- .github/workflows/ci-testing.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-testing.yml b/.github/workflows/ci-testing.yml index 0ec5f5069332..cc374b1c3f50 100644 --- a/.github/workflows/ci-testing.yml +++ b/.github/workflows/ci-testing.yml @@ -111,7 +111,7 @@ jobs: pip --version pip list - python -c "print(str(type(IPython.get_ipython())))" + python -c "import IPython; print(str(type(IPython.get_ipython())))" - name: Test detection shell: bash # for Windows compatibility run: | From cc19dd8d7e2cf4bcbb6befb13c3e40d376d16ea2 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Mon, 17 Oct 2022 13:51:40 +0200 Subject: [PATCH 11/17] fix CI --- .github/workflows/ci-testing.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-testing.yml b/.github/workflows/ci-testing.yml index cc374b1c3f50..15c32f9a7632 100644 --- a/.github/workflows/ci-testing.yml +++ b/.github/workflows/ci-testing.yml @@ -110,7 +110,7 @@ jobs: python --version pip --version pip list - + python -c "import IPython; print(str(type(IPython.get_ipython())))" - name: Test detection shell: bash # for Windows compatibility From 6061c928cac0c64728aa3d100bb0b28da60315e0 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Mon, 17 Oct 2022 13:56:22 +0200 Subject: [PATCH 12/17] fix CI --- .github/workflows/ci-testing.yml | 2 -- utils/general.py | 5 +++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci-testing.yml b/.github/workflows/ci-testing.yml index 15c32f9a7632..1ec68e8412f9 100644 --- a/.github/workflows/ci-testing.yml +++ b/.github/workflows/ci-testing.yml @@ -110,8 +110,6 @@ jobs: python --version pip --version pip list - - python -c "import IPython; print(str(type(IPython.get_ipython())))" - name: Test detection shell: bash # for Windows compatibility run: | diff --git a/utils/general.py b/utils/general.py index 47b721fc0d69..76bc0b1d7a79 100644 --- a/utils/general.py +++ b/utils/general.py @@ -393,8 +393,9 @@ def check_img_size(imgsz, s=32, floor=0): def check_imshow(warn=False): # Check if environment supports image displays try: - assert not is_notebook(), 'cv2.imshow() is disabled in Jupyter notebooks' - assert not is_docker(), 'cv2.imshow() is disabled in Docker containers' + assert not is_notebook() + assert not is_docker() + assert 'NoneType' not in str(type(IPython.get_ipython())) # SSH terminals, GitHub CI cv2.imshow('test', np.zeros((1, 1, 3))) cv2.waitKey(1) cv2.destroyAllWindows() From 5715ea9729160fa1d3192c88fa06495e7759c6a6 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Mon, 17 Oct 2022 14:00:23 +0200 Subject: [PATCH 13/17] fix CI --- .github/workflows/ci-testing.yml | 1 + models/common.py | 7 ++----- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci-testing.yml b/.github/workflows/ci-testing.yml index 1ec68e8412f9..e2977b9c2b12 100644 --- a/.github/workflows/ci-testing.yml +++ b/.github/workflows/ci-testing.yml @@ -133,6 +133,7 @@ jobs: for path in '$m', '$b': model = torch.hub.load('.', 'custom', path=path, source='local') print(model('data/images/bus.jpg')) + model('data/images/bus.jpg').show() model(im) # warmup, build grids for trace torch.jit.trace(model, [im]) EOF diff --git a/models/common.py b/models/common.py index d70549fa0c43..543b4eef41ed 100644 --- a/models/common.py +++ b/models/common.py @@ -18,6 +18,7 @@ import requests import torch import torch.nn as nn +import IPython from PIL import Image from torch.cuda import amp @@ -759,11 +760,7 @@ def _run(self, pprint=False, show=False, save=False, crop=False, render=False, l im = Image.fromarray(im.astype(np.uint8)) if isinstance(im, np.ndarray) else im # from np if show: - if IMSHOW_SUPPORT: - im.show(self.files[i]) - else: - from IPython.display import display - display(im) + im.show(self.files[i]) if IMSHOW_SUPPORT else IPython.display(im) if save: f = self.files[i] im.save(save_dir / f) # save From cc90167ec34bf0c9aa500b82f5737da9ffc2c292 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 17 Oct 2022 12:00:54 +0000 Subject: [PATCH 14/17] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- models/common.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/common.py b/models/common.py index 543b4eef41ed..acdeffd88ec8 100644 --- a/models/common.py +++ b/models/common.py @@ -13,12 +13,12 @@ from urllib.parse import urlparse import cv2 +import IPython import numpy as np import pandas as pd import requests import torch import torch.nn as nn -import IPython from PIL import Image from torch.cuda import amp From 3ac1b0d90b5a0f75563cc7704609a1a2a0620aaf Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Mon, 17 Oct 2022 14:08:46 +0200 Subject: [PATCH 15/17] fix CI --- models/common.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/common.py b/models/common.py index acdeffd88ec8..06d334d264e9 100644 --- a/models/common.py +++ b/models/common.py @@ -760,7 +760,7 @@ def _run(self, pprint=False, show=False, save=False, crop=False, render=False, l im = Image.fromarray(im.astype(np.uint8)) if isinstance(im, np.ndarray) else im # from np if show: - im.show(self.files[i]) if IMSHOW_SUPPORT else IPython.display(im) + im.show(self.files[i]) if IMSHOW_SUPPORT else IPython.display.display(im) if save: f = self.files[i] im.save(save_dir / f) # save From e171dac5b9722fe86c7fd47b8034b77033e59788 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Mon, 17 Oct 2022 14:12:55 +0200 Subject: [PATCH 16/17] fix CI --- utils/__init__.py | 2 +- utils/autoanchor.py | 2 +- utils/metrics.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/utils/__init__.py b/utils/__init__.py index 8403a6149827..0afe6f475625 100644 --- a/utils/__init__.py +++ b/utils/__init__.py @@ -23,7 +23,7 @@ def __enter__(self): def __exit__(self, exc_type, value, traceback): if value: - print(emojis(f'{self.msg}{value}')) + print(emojis(f"{self.msg}{': ' if self.msg else ''}{value}")) return True diff --git a/utils/autoanchor.py b/utils/autoanchor.py index 7e7e9985d68a..cfc4c276e3aa 100644 --- a/utils/autoanchor.py +++ b/utils/autoanchor.py @@ -26,7 +26,7 @@ def check_anchor_order(m): m.anchors[:] = m.anchors.flip(0) -@TryExcept(f'{PREFIX}ERROR: ') +@TryExcept(f'{PREFIX}ERROR') def check_anchors(dataset, model, thr=4.0, imgsz=640): # Check anchor fit to data, recompute if necessary m = model.module.model[-1] if hasattr(model, 'module') else model.model[-1] # Detect() diff --git a/utils/metrics.py b/utils/metrics.py index ed611d7d38fa..f0bc787e1518 100644 --- a/utils/metrics.py +++ b/utils/metrics.py @@ -186,7 +186,7 @@ def tp_fp(self): # fn = self.matrix.sum(0) - tp # false negatives (missed detections) return tp[:-1], fp[:-1] # remove background class - @TryExcept('WARNING ⚠️ ConfusionMatrix plot failure: ') + @TryExcept('WARNING ⚠️ ConfusionMatrix plot failure') def plot(self, normalize=True, save_dir='', names=()): import seaborn as sn From 2329d6ab33b9b78627f5128d5e3e4ebd7be90e8f Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Mon, 17 Oct 2022 14:22:15 +0200 Subject: [PATCH 17/17] fix CI --- .github/workflows/ci-testing.yml | 1 - models/common.py | 6 +++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci-testing.yml b/.github/workflows/ci-testing.yml index e2977b9c2b12..1ec68e8412f9 100644 --- a/.github/workflows/ci-testing.yml +++ b/.github/workflows/ci-testing.yml @@ -133,7 +133,6 @@ jobs: for path in '$m', '$b': model = torch.hub.load('.', 'custom', path=path, source='local') print(model('data/images/bus.jpg')) - model('data/images/bus.jpg').show() model(im) # warmup, build grids for trace torch.jit.trace(model, [im]) EOF diff --git a/models/common.py b/models/common.py index 06d334d264e9..e6da429de3e5 100644 --- a/models/common.py +++ b/models/common.py @@ -13,12 +13,12 @@ from urllib.parse import urlparse import cv2 -import IPython import numpy as np import pandas as pd import requests import torch import torch.nn as nn +from IPython.display import display from PIL import Image from torch.cuda import amp @@ -30,7 +30,7 @@ from utils.plots import Annotator, colors, save_one_box from utils.torch_utils import copy_attr, smart_inference_mode -IMSHOW_SUPPORT = check_imshow() +CHECK_IMSHOW = check_imshow() def autopad(k, p=None, d=1): # kernel, padding, dilation @@ -760,7 +760,7 @@ def _run(self, pprint=False, show=False, save=False, crop=False, render=False, l im = Image.fromarray(im.astype(np.uint8)) if isinstance(im, np.ndarray) else im # from np if show: - im.show(self.files[i]) if IMSHOW_SUPPORT else IPython.display.display(im) + im.show(self.files[i]) if CHECK_IMSHOW else display(im) if save: f = self.files[i] im.save(save_dir / f) # save