0

I'm trying to suppress warnings (specifically from tensorflow) in my Jupyter noteboook since they're not relevant and end up just clogging up my screen and making it super difficult to read the stuff I actually need to read. I've tried everything below, the warnings just won't stop:

  • warnings.filterwarnings('ignore')
  • warnings.simplefilter('ignore')
  • logging.getLogger('tensorflow').disabled = True
  • logging.getLogger('tensorflow').setLevel(logging.ERROR)
  • logging.disable(logging.WARNING)
  • os.environ['PYTHONWARNING'] = 'ignore'
  • os.environ['TF_CPP_MIN_LOG_LEVEL'] = 3

I even tried updating my ipython_config.py file with:

c = get_config()
c.InteractiveShellApp.exec_lines = [
    'import warnings',
    'warnings.filterwarnings("ignore")',
]

And even tried making a context manager like this:

class HiddenPrints:
    def __enter__(self):
        self._original_stderr = sys.stderr
        sys.stderr = open(os.devnull, 'w')

    def __exit__(self, exc_type, exc_val, exc_tb):
        sys.stderr.close()
        sys.stderr = self._original_stderr

with HiddenPrints():
    # rest of my code

For context, I get this warning when I import spacy:

2023-05-23 14:42:41.997371: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations. To enable the following instructions: AVX2 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.

And I get a ton of these warnings when I call a function that builds and fits a LSTM keras model:

2023-05-23 14:48:30.399777: I tensorflow/core/common_runtime/executor.cc:1197] [/device:CPU:0] (DEBUG INFO) Executor start aborting (this does not indicate an error and you can ignore this message): INVALID_ARGUMENT: You must feed a value for placeholder tensor 'gradients/split_2_grad/concat/split_2/split_dim' with dtype int32

I've seen some posts suggest using Jupyter's %%capture magic command, but my understanding is that would capture all output not just warnings which I don't want. Any ideas?

Community
  • 1
  • 1
vudupins
  • 39
  • 6
  • naively, could you fix the warnings? they might be important – ti7 May 23 '23 at 18:08
  • Please share a toy example of a shareable, minimal reproducible example, as detailed in [How do I ask a good question?](https://stackoverflow.com/help/how-to-ask), so that those knowledgeable can try the tricks we know about and put you on track. There are different levels of the stdout/stderr pipes to address. This is already partly covered **in general** in several places in StackOverflow, such as [here](https://stackoverflow.com/a/23692951/8508004) or [here](https://stackoverflow.com/a/52559560/8508004) & others. And so if you want more specific advice, post an improved question. – Wayne May 23 '23 at 18:26
  • Hi @vudupins, Did you try using `import os`, `os.environ['TF_CPP_MIN_LOG_LEVEL']='2'` before importing the tensorflow in your code to suppress the warning messages? Please refer to this [link](https://stackoverflow.com/a/76315324/21904865) for your reference. Let us know if the issue still persists. – TF_Renu Patel Jun 24 '23 at 07:24

0 Answers0