Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I stop Keras showing "using XXX backend"?

Tags:

python

keras

"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?

like image 948
fmnijk Avatar asked Jul 21 '18 14:07

fmnijk


3 Answers

Just using the code below.

import os
import sys
stderr = sys.stderr
sys.stderr = open(os.devnull, 'w')
import keras
sys.stderr = stderr
like image 161
fmnijk Avatar answered Sep 19 '22 03:09

fmnijk


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

like image 36
Tal Avissar Avatar answered Sep 23 '22 03:09

Tal Avissar


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)

like image 31
Ankit Jain Avatar answered Sep 20 '22 03:09

Ankit Jain