profile
viewpoint

Ask questionsTf.Keras metrics issue

<em>Please make sure that this is a bug. As per our GitHub Policy, we only address code/doc bugs, performance issues, feature requests and build/installation issues on GitHub. tag:bug_template</em>

System information

  • Have I written custom code (as opposed to using a stock example script provided in TensorFlow): NO
  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Windows 10
  • Mobile device (e.g. iPhone 8, Pixel 2, Samsung Galaxy) if the issue happens on mobile device: NO
  • TensorFlow installed from (source or binary): Source ( Pip )
  • TensorFlow version (use command below): 1.13
  • Python version: 3.6.7

You can collect some of this information using our environment capture script You can also obtain the TensorFlow version with python -c "import tensorflow as tf; print(tf.GIT_VERSION, tf.VERSION)"

1.13.1

Describe the current behavior I need to use Keras metric while compiling an LSTM model. it is getting compiled. But when I started to train I am getting error.

my code looks as follows :

model = Sequential()
model.add(LSTM (120,activation = "tanh", input_shape=(timesteps,dim), return_sequences=True))
model.add(LSTM(120, activation = "tanh", return_sequences=True))
model.add(LSTM(120, activation = "tanh", return_sequences=True))
model.add(LSTM(120, activation = "tanh", return_sequences=True))
model.add(LSTM(120, activation = "tanh", return_sequences=True))
model.add(LSTM(120, activation = "tanh", return_sequences=True))
model.add(Dense(dim))
model.compile(optimizer="adam", loss="mse",  metrics=[tf.keras.metrics.Precision()])

history = model.fit(data,data, 
                    epochs=100,
                    batch_size=10,
                    validation_split=0.2,
                    shuffle=True,
                    callbacks=[ch]).history

There error I am getting as follows

InvalidArgumentError: assertion failed: [predictions must be >= 0] [Condition x >= y did not hold element-wise:x (dense_3/BiasAdd:0) = ] [[[2.72658144e-06 1.17555362e-06 1.96436554e-06...]]...] [y (metrics_3/precision_1/Cast/x:0) = ] [0] [[{{node metrics_3/precision_1/assert_greater_equal/Assert/AssertGuard/Assert}}]]

tensorflow/tensorflow

Answer questions pavithrasv

@AkbarAlam Precision metric takes predictions as probabilities, hence the error predictions must be >= 0. For this you will need to add sigmoid (if dim == 1) or softmax (for dim > 1) activation function to the last dense layer.

useful!

Related questions

ModuleNotFoundError: No module named 'tensorflow.contrib' hot 8
Error occurred when finalizing GeneratorDataset iterator hot 7
tensorflow-gpu CUPTI errors
Error loading tensorflow
ModuleNotFoundError: No module named 'tensorflow.contrib'
module 'tensorflow' has no attribute 'ConfigProto'
TF 2.0 'Tensor' object has no attribute 'numpy' while using .numpy() although eager execution enabled by default
When importing TensorFlow, error loading Hadoop
AttributeError: module &#39;tensorflow.python.framework.op_def_registry&#39; has no attribute &#39;register_op_list&#39;
tf.keras.layers.Conv1DTranspose ?
[TF 2.0] tf.keras.optimizers.Adam hot 4
Lossy conversion from float32 to uint8. Range [0, 1]. Convert image to uint8 prior to saving to suppress this warning. hot 4
TF2.0 AutoGraph issue hot 4
ModuleNotFoundError: No module named 'tensorflow.examples.tutorials' hot 4
module 'tensorflow.python._pywrap_tensorflow_internal' has no attribute 'TFE_NewContextOptions' hot 4
Github User Rank List