【问题标题】:To pick the most confident data samples(top 3) per class based on the softmax output根据 softmax 输出为每个类别挑选最有信心的数据样本(前 3 个)
【发布时间】:2020-01-17 06:35:18
【问题描述】:

所以我已经在一个包含 50 个类别的特定数据集上训练了一个神经网络。在测试过程中,我想从测试数据集中的每个类中选择最好的三个样本(最有信心的样本,即前 3 或前 5 样本),我该怎么做?

示例:如果我有 50 个类,我想为每个类从测试数据集中挑选 3 个最佳样本(基于 softmax 概率)。因此,我们将选择 50*3 个数据样本。我怎样才能以最有效的方式做到这一点?

谢谢。

【问题讨论】:

    标签: deep-learning neural-network artificial-intelligence sampled-softmax


    【解决方案1】:

    假设您的最终分数在张量 probabilities 中,即测试数据的形状大小 × 类数,我会这样做:

    best_scores, best_classes = probabilities.max(dim=1)
    
    per_class_examples = []
    for class_id in range(50):
        # mask telling where class_id class is
        class_positions = best_classes == class_id
    
        # make sure there are at least three examples,
        # if not, rather take less
        k = min(3, class_positions.sum())
    
        if k == 0:
            per_class_examples.append([])
        else:
            # set zero score to everything that is not class_id
            _, best_examples = torch.topk(best_scores * class_positions, k, dim=1)
            per_class_examples.append(best_examples)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-08-23
      • 2019-11-03
      • 2015-01-03
      • 2015-01-08
      • 2020-04-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-29
      相关资源
      最近更新 更多