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
model.py 文件源码
python
阅读 19
收藏 0
点赞 0
评论 0
评论列表
文章目录