diff --git a/utils/general.py b/utils/general.py index 470e6d81d250..bce2a1763e2a 100755 --- a/utils/general.py +++ b/utils/general.py @@ -44,10 +44,21 @@ 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)