Add is_kaggle() function (#6285)
* Add `is_kaggle()` function Return True if environment is Kaggle Notebook. * Remove root loggers only if is_kaggle() == True * Update general.py
This commit is contained in:
1 parent
80473a6551
commit
af001349e4
1 file changed
+13
-2
+13
-2
@@ -44,10 +44,21 @@ cv2.setNumThreads(0) # prevent OpenCV from multithreading (incompatible with Py
|
||||
os.environ['NUMEXPR_MAX_THREADS'] = str(NUM_THREADS) # NumExpr max threads
|
||||
|
||||
|
||||
def is_kaggle():
|
||||
# Is environment a Kaggle Notebook?
|
||||
try:
|
||||
assert os.environ.get('PWD') == '/kaggle/working'
|
||||
assert os.environ.get('KAGGLE_URL_BASE') == 'https://www.kaggle.com'
|
||||
return True
|
||||
except AssertionError:
|
||||
return False
|
||||
|
||||
|
||||
def set_logging(name=None, verbose=True):
|
||||
# Sets level and returns logger
|
||||
for h in logging.root.handlers:
|
||||
logging.root.removeHandler(h) # remove all handlers associated with the root logger object
|
||||
if is_kaggle():
|
||||
for h in logging.root.handlers:
|
||||
logging.root.removeHandler(h) # remove all handlers associated with the root logger object
|
||||
rank = int(os.getenv('RANK', -1)) # rank in world for Multi-GPU trainings
|
||||
logging.basicConfig(format="%(message)s", level=logging.INFO if (verbose and rank in (-1, 0)) else logging.WARNING)
|
||||
return logging.getLogger(name)
|
||||
|
||||
Reference in new issue
Block a user