glenn-jocher
commited on
Commit
•
af00134
1
Parent(s):
80473a6
Add `is_kaggle()` function (#6285)
Browse files* Add `is_kaggle()` function
Return True if environment is Kaggle Notebook.
* Remove root loggers only if is_kaggle() == True
* Update general.py
- utils/general.py +13 -2
utils/general.py
CHANGED
@@ -44,10 +44,21 @@ cv2.setNumThreads(0) # prevent OpenCV from multithreading (incompatible with Py
|
|
44 |
os.environ['NUMEXPR_MAX_THREADS'] = str(NUM_THREADS) # NumExpr max threads
|
45 |
|
46 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
def set_logging(name=None, verbose=True):
|
48 |
# Sets level and returns logger
|
49 |
-
|
50 |
-
logging.root.
|
|
|
51 |
rank = int(os.getenv('RANK', -1)) # rank in world for Multi-GPU trainings
|
52 |
logging.basicConfig(format="%(message)s", level=logging.INFO if (verbose and rank in (-1, 0)) else logging.WARNING)
|
53 |
return logging.getLogger(name)
|
|
|
44 |
os.environ['NUMEXPR_MAX_THREADS'] = str(NUM_THREADS) # NumExpr max threads
|
45 |
|
46 |
|
47 |
+
def is_kaggle():
|
48 |
+
# Is environment a Kaggle Notebook?
|
49 |
+
try:
|
50 |
+
assert os.environ.get('PWD') == '/kaggle/working'
|
51 |
+
assert os.environ.get('KAGGLE_URL_BASE') == 'https://www.kaggle.com'
|
52 |
+
return True
|
53 |
+
except AssertionError:
|
54 |
+
return False
|
55 |
+
|
56 |
+
|
57 |
def set_logging(name=None, verbose=True):
|
58 |
# Sets level and returns logger
|
59 |
+
if is_kaggle():
|
60 |
+
for h in logging.root.handlers:
|
61 |
+
logging.root.removeHandler(h) # remove all handlers associated with the root logger object
|
62 |
rank = int(os.getenv('RANK', -1)) # rank in world for Multi-GPU trainings
|
63 |
logging.basicConfig(format="%(message)s", level=logging.INFO if (verbose and rank in (-1, 0)) else logging.WARNING)
|
64 |
return logging.getLogger(name)
|