model.py 文件源码

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

项目:deep-learning-for-human-part-discovery-in-images 作者: shiba24 项目源码 文件源码
def calculate_accuracy(self, predictions, truths):
        if cuda.get_array_module(predictions.data) == cuda.cupy:
            with predictions.data.device:
                predictions =  predictions.data.get()
            with truths.data.device:
                truths = truths.data.get()
        else:
            predictions = predictions.data
            truths = truths.data

        # we want to exclude labels with -1
        mask = truths != -1
        # reduce values along classe axis
        reduced_preditions = np.argmax(predictions, axis=1) 
        # mask
        masked_reduced_preditions = reduced_preditions[mask]
        masked_truths = truths[mask] 
        s = (masked_reduced_preditions == masked_truths).mean()
        return s
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号