Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable keras warnings?

When I run the following code:

init = "he_uniform"

inp = Input(shape=(1800, 1))
norm1 = BatchNormalization(mode=0)(inp)
conv1 = Convolution1D(16, 5,  border_mode='same', init=init, activation="relu")(norm1)
pool1 = MaxPooling1D(pool_size=3)(conv1)
norm2 = BatchNormalization(mode=0)(pool1)
flat1 = Flatten()(norm2)
dens1 = Dense(128, init=init, activation="relu")(flat1)
#norm3 = BatchNormalization(mode=0)(dens1)
output = Dense(2, init=init, activation="softmax")(dens1)
from keras.models import *
model = Model(input=[inp], output=output)

I had the warnings:

root/miniconda/envs/jupyterhub_py3/lib/python3.4/site-packages/ipykernel/__main__.py:4: UserWarning: Update your `BatchNormalization` call to the Keras 2 API: `BatchNormalization()`
/root/miniconda/envs/jupyterhub_py3/lib/python3.4/site-packages/ipykernel/__main__.py:5: UserWarning: Update your `Conv1D` call to the Keras 2 API: `Conv1D(16, 5, activation="relu", kernel_initializer="he_uniform", padding="same")`
/root/miniconda/envs/jupyterhub_py3/lib/python3.4/site-packages/ipykernel/__main__.py:7: UserWarning: Update your `BatchNormalization` call to the Keras 2 API: `BatchNormalization()`
/root/miniconda/envs/jupyterhub_py3/lib/python3.4/site-packages/ipykernel/__main__.py:9: UserWarning: Update your `Dense` call to the Keras 2 API: `Dense(128, activation="relu", kernel_initializer="he_uniform")`

The following approach did not help.

with warnings.catch_warnings():
    warnings.simplefilter("ignore")

How to disable this warning?

like image 427
Толкачёв Иван Avatar asked May 06 '17 11:05

Толкачёв Иван


People also ask

How to turn off TensorFlow warnings in keras?

These warnings are about how Keras uses TensorFlow. The people who maintain Keras are the ones who can fix them. The warnings in TensorFlow could be managed by the tf.logging module. To turn off the warnings you can use,

What do these keras warnings mean?

From within python: The warnings indicate you are using keras 1.x code with a keras 2.x installation. Maybe it would be easier to fix them, instead of ignoring. Show activity on this post.

Is it safe to use a deprecation notice for keras?

a deprecation notice means it works but will soon be removed. so if you are maintaining this code, you should replace it. but for a one off investigation, it's fine. These warnings are about how Keras uses TensorFlow. The people who maintain Keras are the ones who can fix them.

What is the learning rate of Keras?

Using a start/stop/resume training approach with Keras, we have achieved 94.14% validation accuracy. At this point the learning rate has become so small that the corresponding weight updates are also very small, implying that the model cannot learn much more. I only allowed training to continue for 5 epochs before killing the script.


2 Answers

You can tell tensorflow using environment variables. From within python:

import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'

The warnings indicate you are using keras 1.x code with a keras 2.x installation. Maybe it would be easier to fix them, instead of ignoring.

like image 150
gessulat Avatar answered Sep 24 '22 16:09

gessulat


You can use this code at the top of the main.py:

def warn(*args, **kwargs):
    pass
import warnings
warnings.warn = warn
like image 30
ykpgrr Avatar answered Sep 26 '22 16:09

ykpgrr