mAP for a single image

I am building a model that requires calculating the mAP per image (I’d call it running mAP) for evaluation. The way I’ve been doing it is as follows:

aps = []
existing_class = np.unique(truth[:, -1])
for classidx in existing_class:
	if truth[truth[:, -1] == classidx].size > 0:
		rec, prec, ap = compute_overlap(classidx, pred_boxes, pred_confs, pred_labels, truth)
mean_ap = np.mean(aps)

Basically, it iterates only over the existing classes in the respective image, unlike the original implementation, where for overall evaluation the computation iterates over all classes, 20 on Pascal VOC or 9 on KITTI.

I’ve been wondering if it makes sense to do it the way I do with the code snippet I just posted.
Looking forward to exchange!