glenn-jocher
commited on
Commit
•
fcd5702
1
Parent(s):
e2a80c6
Add is_colab() function (#3018)
Browse files- utils/general.py +13 -3
utils/general.py
CHANGED
@@ -51,11 +51,20 @@ def get_latest_run(search_dir='.'):
|
|
51 |
return max(last_list, key=os.path.getctime) if last_list else ''
|
52 |
|
53 |
|
54 |
-
def
|
55 |
# Is environment a Docker container
|
56 |
return Path('/workspace').exists() # or Path('/.dockerenv').exists()
|
57 |
|
58 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
def emojis(str=''):
|
60 |
# Return platform-dependent emoji-safe version of string
|
61 |
return str.encode().decode('ascii', 'ignore') if platform.system() == 'Windows' else str
|
@@ -81,7 +90,7 @@ def check_git_status():
|
|
81 |
print(colorstr('github: '), end='')
|
82 |
try:
|
83 |
assert Path('.git').exists(), 'skipping check (not a git repository)'
|
84 |
-
assert not
|
85 |
assert check_online(), 'skipping check (offline)'
|
86 |
|
87 |
cmd = 'git fetch && git config --get remote.origin.url'
|
@@ -138,7 +147,8 @@ def check_img_size(img_size, s=32):
|
|
138 |
def check_imshow():
|
139 |
# Check if environment supports image displays
|
140 |
try:
|
141 |
-
assert not
|
|
|
142 |
cv2.imshow('test', np.zeros((1, 1, 3)))
|
143 |
cv2.waitKey(1)
|
144 |
cv2.destroyAllWindows()
|
|
|
51 |
return max(last_list, key=os.path.getctime) if last_list else ''
|
52 |
|
53 |
|
54 |
+
def is_docker():
|
55 |
# Is environment a Docker container
|
56 |
return Path('/workspace').exists() # or Path('/.dockerenv').exists()
|
57 |
|
58 |
|
59 |
+
def is_colab():
|
60 |
+
# Is environment a Google Colab instance
|
61 |
+
try:
|
62 |
+
import google.colab
|
63 |
+
return True
|
64 |
+
except Exception as e:
|
65 |
+
return False
|
66 |
+
|
67 |
+
|
68 |
def emojis(str=''):
|
69 |
# Return platform-dependent emoji-safe version of string
|
70 |
return str.encode().decode('ascii', 'ignore') if platform.system() == 'Windows' else str
|
|
|
90 |
print(colorstr('github: '), end='')
|
91 |
try:
|
92 |
assert Path('.git').exists(), 'skipping check (not a git repository)'
|
93 |
+
assert not is_docker(), 'skipping check (Docker image)'
|
94 |
assert check_online(), 'skipping check (offline)'
|
95 |
|
96 |
cmd = 'git fetch && git config --get remote.origin.url'
|
|
|
147 |
def check_imshow():
|
148 |
# Check if environment supports image displays
|
149 |
try:
|
150 |
+
assert not is_docker(), 'cv2.imshow() is disabled in Docker environments'
|
151 |
+
assert not is_colab(), 'cv2.imshow() is disabled in Google Colab environments'
|
152 |
cv2.imshow('test', np.zeros((1, 1, 3)))
|
153 |
cv2.waitKey(1)
|
154 |
cv2.destroyAllWindows()
|