Implement Accuracy with Masking in TensorFlow – TensorFlow Tutorial

By | August 24, 2020

Accuracy is an important metrics to evaluate the ai model. In this tutorial, we will introduce how to calculate accuracy with maksing in TensorFlow.

Following by softmax and sigmoid cross-entropy loss with masking. We also can build a tensorflow function to calculate the accuracy with maksing in TensorFlow.

Implement Softmax Cross-entropy Loss with Masking in TensorFlow – TensorFlow Tutorial

Implement Sigmoid Cross-entropy Loss with Masking in TensorFlow – TensorFlow Tutorial

Calculate accuracy with maksing in TensorFlow

Here we will create a function masked_accuracy() to compute.

    def masked_accuracy(logits, labels, mask):
        """Accuracy with masking."""
        correct_prediction = tf.equal(tf.argmax(logits, 1), tf.argmax(labels, 1))
        accuracy_all = tf.cast(correct_prediction, tf.float32)
        mask = tf.cast(mask, dtype=tf.float32)
        mask /= tf.reduce_mean(mask)
        accuracy_all *= mask
        return tf.reduce_mean(accuracy_all)

Leave a Reply