| |
| """ |
| Module to suppress various warnings and logging |
| Import this FIRST to ensure warnings are suppressed before other imports |
| """ |
|
|
| import os |
| import sys |
| import warnings |
| import logging |
|
|
| def suppress_all_warnings(): |
| """Suppress all common warnings from ML libraries""" |
| |
| |
| os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' |
| os.environ['TF_ENABLE_ONEDNN_OPTS'] = '0' |
| os.environ['PYTHONWARNINGS'] = 'ignore' |
| |
| |
| warnings.filterwarnings('ignore') |
| warnings.simplefilter('ignore') |
| |
| |
| warnings.filterwarnings('ignore', category=DeprecationWarning) |
| warnings.filterwarnings('ignore', category=FutureWarning) |
| warnings.filterwarnings('ignore', category=UserWarning) |
| warnings.filterwarnings('ignore', category=RuntimeWarning) |
| |
| |
| try: |
| import tensorflow as tf |
| tf.get_logger().setLevel('ERROR') |
| tf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.ERROR) |
| |
| |
| tf.config.run_functions_eagerly(False) |
| |
| except ImportError: |
| pass |
| |
| |
| logging.getLogger('mediapipe').setLevel(logging.ERROR) |
| logging.getLogger('absl').setLevel(logging.ERROR) |
| logging.getLogger('absl.logging').setLevel(logging.ERROR) |
| |
| |
| try: |
| import torch |
| torch.set_num_threads(1) |
| except ImportError: |
| pass |
| |
| |
| for logger_name in [ |
| 'h5py', 'PIL', 'matplotlib', 'sklearn', |
| 'scipy', 'numpy', 'pandas', 'cv2' |
| ]: |
| logging.getLogger(logger_name).setLevel(logging.ERROR) |
|
|
| |
| suppress_all_warnings() |