Allow PyTorch Hub results to display in notebooks (#9825)
* Allow PyTorch Hub results to display in notebooks * fix CI * fix CI * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix CI * fix CI * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix CI * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix CI * fix CI * fix CI * fix CI * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix CI * fix CI * fix CI Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
1 parent
e42c89d4ef
commit
e3ff780676
8 files changed
+28
-14
No files matched your search
+13
-4
@@ -27,6 +27,7 @@ from typing import Optional
|
||||
from zipfile import ZipFile
|
||||
|
||||
import cv2
|
||||
import IPython
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
import pkg_resources as pkg
|
||||
@@ -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'
|
||||
@@ -383,18 +390,20 @@ 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_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()
|
||||
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
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user