WARNING:tensorflow with constraint is deprecated and will be removed in a future version
Asked Answered
H

6

8

I am following Tensorflow's tutorial on building a simple neural network, and after importing the necessary libraries (tensorflow, keras, numpy & matplotlib) and datasets (fashion_mnist) I ran this code as per the tutorial:

model = keras.Sequential([
    keras.layers.Flatten(input_shape=(28, 28)),
    keras.layers.Dense(128, activation='relu'),
    keras.layers.Dense(10, activation='softmax')
]) 

after running this code i received this warning message:

WARNING:tensorflow:From /Applications/anaconda3/envs/tensorfloe/lib/python3.7/site-packages/tensorflow_core/python/ops/resource_variable_ops.py:1630: calling BaseResourceVariable.init (from tensorflow.python.ops.resource_variable_ops) with constraint is deprecated and will be removed in a future version. Instructions for updating: If using Keras pass *_constraint arguments to layers.

How do i fix this? Your help is highly appreciated.

Hypothecate answered 8/2, 2020 at 19:55 Comment(0)
G
11

This is internal TensorFlow message, you can safely ignore it. It will be gone in future versions of TensorFlow, no actions from your side is needed.

Grondin answered 8/2, 2020 at 20:9 Comment(2)
Why is the message here, when we are supposed to ignore it? Do you have any information from tensorflow issues on that topic?Turnage
@gessulat, what Vladimir told is that this warning is due to an internal tensorflow issue, tensorflow is using its own libraries in a deprecated way, at some point in the future when the deprecated function no longer works, they will have this fixed. The error message Fikile posted has info about what fires it.Entryway
H
2

I had a similar warning when I was using tf.compat.v1.get_variable(...) and what I needed to do was to set the use_resource argument to False. Might help someone looking for a similar warning but doesn't look like the case with you though.

Hakluyt answered 30/6, 2020 at 3:21 Comment(0)
E
1

Well it is a warning that some features are deprecated and will be removed in a future version. It is just for your information that what changes could occur. Although, you can remove these warnings by

import warnings
warnings.filterwarnings("ignore", category=DeprecationWarning) 
Endblown answered 9/2, 2020 at 19:59 Comment(0)
S
0

If you only want to filter the tensorflow logs, you can disable the logging with the following lines (tensorflow 2.2):

import tensorflow as tf   
tf.get_logger().setLevel('ERROR')
Somewhere answered 5/7, 2020 at 11:29 Comment(0)
P
0
## Before code 
    embedding_vector_features = 40
    model = Sequential()
       model.add(Embedding(voc_size,embedding_vector_features, 
    input_length = sent_length))
    model.add(LSTM(100))
    model.add(Dense(1, activation = 'sigmoid'))
    model.compile(loss = 'binary_crossentropy', optimizer = 'adam', metrics = ['accuracy'])
    print(model.summary())

# after code 
   embedding_vector_features = 40
    model = Sequential()
 
 
 
 model.add(Embedding(voc_size,embedding_vector_features))
    model.add(LSTM(100))
    model.add(Dense(1, activation = 'sigmoid'))
    model.compile(loss = 'binary_crossentropy', optimizer = 'adam', metrics = ['accuracy'])
    model.build(input_shape=(None, sent_length)) 
    `enter code here`print(model.summary())
Projector answered 8/8 at 11:52 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Demimonde
D
-3

if you want to remove it , you can do run twice for the line of code.

Dysfunction answered 17/5, 2020 at 1:15 Comment(3)
Wouldn't he still get the warning the first time?Psychodrama
Hey Anas, Welcome to StackOverflow. Either you should explain your answer with properly formated output in ANswer section or if there is only one-liner answer you should add it in a comment. You can check this answering guideline as well stackoverflow.com/help/how-to-answerLotson
Anas is talking about jupyter notebook. On running notebook cell first time, if cell gives warning run it again, cell will not show warning message.Endblown

© 2022 - 2024 — McMap. All rights reserved.