inputs.py 文件源码

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

项目:segmentation 作者: zengyu714 项目源码 文件源码
def weights_map(ys):
    """Compute corresponding weight map when use cross entropy loss.

    Argument:
        ys: [depth, height, width]

    Return:
        weights_map: [depth, height, width]
    """
    weights = ys.astype(np.float64)

    # Balance class frequencies.
    cls_ratio = np.sum(1 - ys) / np.sum(ys)
    weights *= cls_ratio

    # Generate boundaries using morphological operation.
    se = generate_binary_structure(3, 1)
    bigger = binary_dilation(ys, structure=se).astype(np.float64)
    small = binary_erosion(ys, structure=se).astype(np.float64)
    edge = bigger - small

    # Balance edge frequencies.
    edge_ratio = np.sum(bigger) / np.sum(edge)
    edge *= np.exp(edge_ratio) * 10

    # `weights` should > 0
    # `targets * -log(sigmoid(logits)) * pos_weight + (1 - targets) * -log(1 - sigmoid(logits))`
    return weights + edge + 1
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号