Skip to content

KeyError cumulative_true_positives[class_id] #368

Open
@d-simple

Description

@d-simple

In ssd300_evaluation.ipynb when running evaluation
with custom/cut dataset there can be zero predictions for specific class which results in KeyError on line

average_precision_evaluator.py
...
def compute_precision_recall(...)
...
tp = self.cumulative_true_positives[class_id] 

This is because match_predictions function skips adding zero-prediction classes to the self.cumulative_true_positives list.
The function has conditional block

if len(predictions) == 0:
    print("No predictions for class {}/{}".format(class_id, self.n_classes))
    true_positives.append(true_pos)
    false_positives.append(false_pos)
    continue

that should resolve the issue but it does so incompletely.

Fixing it like so

if len(predictions) == 0:
    print("No predictions for class {}/{}".format(class_id, self.n_classes))
    true_positives.append(true_pos)
    false_positives.append(false_pos)
    
    cumulative_true_pos = np.cumsum(true_pos)
    cumulative_false_pos = np.cumsum(false_pos)

    cumulative_true_positives.append(cumulative_true_pos)
    cumulative_false_positives.append(cumulative_false_pos)
    continue

resolves the issue (but does not help your model :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions