metrics.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:tefla 作者: openAGI 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号