Useful or not, from you.
tensorflow Tf.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}}]]

That's a useful answer
Without any help

@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.