import torch


def clsmap2scoremap(cls_maps, use_softmax=False, Cat=80, Anchor=9, score_shel=0):
    """
    
    :param cls_maps: Cat * Anchor x H x W
    :param use_softmax: score如果使用了sigmoid，就可以不进行softmax操作, use_softmax可以设置为False
    :param Cat: 类别
    :param Anchor: Anchor个数
    :param score_shel: score threshold
    :return: score_maps: Anchor x H x W，每个anchor的最大score
             cat_maps: Cat x H x W，每个anchor的最大score对应的category   
    """
    map = torch.Tensor(cls_maps)
    assert map.shape[0] == Cat * Anchor
    _, H, W = cls_maps.shape
    score_maps = torch.zeros(Anchor, H, W)
    cat_maps = torch.zeros(Anchor, H, W)
    # 将map的每一个Anchor对应的那些channel转换为one_hot编码，并且滤除掉小于指定阈值的位置
    for a in range(Anchor):
        score_map = map[a * Cat: (a + 1) * Cat]
        if use_softmax:
            score_map = score_map.softmax(0)
        (max_score, ind) = torch.max(score_map, 0)
        cat_maps[a] = ind

        max_score[max_score <= score_shel] = 0
        score_maps[a] = max_score

    return score_maps, cat_maps