Update accuracy.py

This commit is contained in:
bjutsecurity22 2023-09-18 19:22:22 +08:00
parent a7c1bbffae
commit c61c5634c7
1 changed files with 3 additions and 3 deletions

View File

@ -84,7 +84,7 @@ class Accuracy(EvaluationBase):
@rearrange_inputs
def update(self, *inputs):
# 更新本地变量。对于分类任务,如果预测值的索引与标签相匹配,则认为预测结果正确。对于多标签任务,如果预测值与标签相匹配,则认为预测结果正确
# 更新本地变量。对于分类任务,如果预测值的索引与标签相匹配,则认为预测结果正确。对于多标签任务,如果预测值与标签相匹配,则认为预测结果正确
"""
Updates the local variables. For 'classification', if the index of the maximum of the predict value
matches the label, the predict result is correct. For 'multilabel', the predict value match the label,
@ -114,7 +114,7 @@ class Accuracy(EvaluationBase):
y_pred = self._convert_data(inputs[0])
# 将data型的输入值inputs[1]转换为numpy数组
y = self._convert_data(inputs[1])
# 根据self._type的值判断是分类任务还是多标签任务
# 根据self._type的值判断是分类任务还是多标签任务
if self._type == 'classification' and y_pred.ndim == y.ndim and _check_onehot_data(y):
# 对于分类任务如果y_pred和y的维度相同并且y是onehot编码的则将y的维度降低到一个维度
y = y.argmax(axis=1)
@ -131,7 +131,7 @@ class Accuracy(EvaluationBase):
"classes, but current predicted data contain {} classes, please check your predicted "
"value(inputs[0]).".format(self._class_num, y_pred.shape[1]))
# 根据self._type的值判断是分类任务还是多标签任务
# 根据self._type的值判断是分类任务还是多标签任务
if self._type == 'classification':
# 对于分类任务将y_pred的维度降低到一个维度
indices = y_pred.argmax(axis=1)