テンソルフローの平均二乗誤差を使用してネットワークの損失を計算しようとしていますが、何らかの理由で、入力テンソルに数値が 1 つしかない場合は機能しません。代わりにこれを行う方法。
ここにいくつかのコードがあります:
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)
エラー
tensorflow.python.framework.errors_impl.InvalidArgumentError: 無効な縮小次元 (0 次元の入力の場合は -1) [Op:Mean]