Reputation: 457
"Using XXX backend" would print when I import keras.
import keras
Outputs:
Using TensorFlow backend.
But I clearly know what I am using.
How to disable it?
Upvotes: 7
Views: 9121
Reputation: 91
Another way to hide keras printing "using Tensorflow backend"
Suggested here https://github.com/keras-team/keras/issues/1406
import ...
import os
from contextlib import redirect_stderr
with redirect_stderr(open(os.devnull, "w")):
import keras
import ...
import ...
Upvotes: 0
Reputation: 1
First comment in here "keras/backend/init.py" the string print('Using TensorFlow backend.') it will work!!.. but it is not a permanent solution.
Upvotes: 0
Reputation: 243
If you are using Tensorflow 2.0
, then you might get an error saying AttributeError: module 'tf' has no attribute 'logging'
Unfortunately tf.logging
has been removed from tensorflow 2.0
. Please execute the below commands:
import logging
logger = tf.get_logger()
logger.setLevel(logging.ERROR)
Upvotes: 1
Reputation: 243
Include this line in your code. It will ignore the error.
tf.logging.set_verbosity(tf.logging.ERROR)
Upvotes: -1
Reputation: 457
Just using the code below.
import os
import sys
stderr = sys.stderr
sys.stderr = open(os.devnull, 'w')
import keras
sys.stderr = stderr
Upvotes: 9
Reputation: 10314
workaround for this problem:
stderr = sys.stderr
sys.stderr = open(os.devnull, 'w')
import keras
sys.stderr = stderr
You can find more info in keras issues here
Upvotes: 4
Reputation: 541
You have two options:
First comment in here keras/backend/__init__.py
the string print('Using TensorFlow backend.')
, but of course this option is not suggested since you are going to edit code in the keras module.
The second option is:
import sys
stdout = sys.stdout
sys.stdout = open('/dev/null', 'w')
import keras
sys.stdout = stdout
It's not elegant, but it works.
Upvotes: 0