I am trying calculate the loss of a network with tensorflow mean squared error, but for some reason it doesn't work if the input tensors only have one number. How should do this instead.
Here is some code:
import tensorflow as tf
loss = tf.keras.losses.MeanSquaredError()
a = loss(y_true=tf.constant([1.0, 2.0, 3.0]), y_pred=tf.constant([2.0, 2.0, 4.0]))
print(a)
a = loss(y_true=tf.constant(1.0, dtype=tf.float32), y_pred=tf.constant(2.0, dtype=tf.float32)) #this is where the error occurs.
print(a)
error
tensorflow.python.framework.errors_impl.InvalidArgumentError: Invalid reduction dimension (-1 for input with 0 dimension(s) [Op:Mean]