我使用for循环来计算y_pred和y_true之间的精度,这使我的代码非常慢,因此我想避免这种for循环。如何更改此代码?
sumAcc = tf.Variable(0, dtype=tf.float32)
for i in range(0, y_pred_batch_size):
ele_y_pred = y_pred[i, 0:label_length[i,0]]
ele_y_true = y_true[i, 0:label_length[i,0]]
sumAcc = sumAcc + tf.reduce_mean(tf.cast(tf.equal( ele_y_pred, ele_y_true), tf.float32))
tf.print("\n","Accuracy: ",sumAcc / tf.constant(y_pred_batch_size,dtype=tf.float32) * 100,"%" )
y_pred和y_true的值看起来像.. [batch_index, [[45],[56],[12],...]