def metric(self, predictions, targets, num_classes=None, batch_size=None, **kwargs):
"""
Computes Kappa metric
Args:
predictions: 2D tensor/array, predictions of the network
targets: 2D tensor/array, ground truth labels of the network
num_classes: int, num_classes of the network
batch_size: batch_size for predictions of the network
Returns:
Kappa score
"""
if num_classes is None:
num_classes = self.num_classes
if batch_size is None:
batch_size = self.batch_size
targets = tf.convert_to_tensor(targets)
predictions = tf.convert_to_tensor(predictions)
if targets.get_shape().ndims == 1:
targets = tf.one_hot(targets, num_classes, on_value=1, off_value=0)
if predictions.get_shape().ndims == 1:
predictions = tf.one_hot(
predictions, num_classes, on_value=1, off_value=0)
return self._kappa_loss(predictions, targets, batch_size=batch_size, num_ratings=num_classes, **kwargs)
评论列表
文章目录