pierluigiferrari / ssd_keras

A Keras port of Single Shot MultiBox Detector
Apache License 2.0
1.86k stars 934 forks source link

KeyError cumulative_true_positives[class_id] #368

Open d-simple opened 3 years ago

d-simple commented 3 years ago

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 :)

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.