ssd_keras icon indicating copy to clipboard operation
ssd_keras copied to clipboard

KeyError cumulative_true_positives[class_id]

Open d-simple opened this issue 4 years ago • 1 comments

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

d-simple avatar Dec 15 '20 13:12 d-simple

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.

stale[bot] avatar Dec 25 '20 12:12 stale[bot]