Tips & Trick & Best Practices in training (not only) object detection models

:tada: Here is Part 2- Summary of 10 summaries on:

Tips & Trick & Best Practices in training (not only) object detection models.

:gift: Summary of summaries:

1- Training Object Detection Models Tips & Tricks

2- Pro Tip to fast track your object detection training

3- Detecting small object detection using SAHI and IceVision

4- How to increase your Small Object Detection Average Precision APs

5- Pro Tip: Increase the number of detections per image if your image has more than 100 bounding boxes.

6- How to create a robustness evaluation dataset?

7- A Survey of Self-Supervised and Few-Shot Object Detection (FSOD).

8- A Comparative Review of Recent Few-Shot Object Detection Algorithms

9- Multi-Task Self-Training (MuST) for Learning General Representations

10- Using IceVision in Kaggle Competitions

If you find those summaries helpful, please share, and help others discover that content. :pray:

10 Likes

How to get the number of positve and negative predcitions from object detection model like retinanet?
I used the following code to compute AP:

def compute_class_AP(model, dl, n_classes, iou_thresh=0.5, detect_thresh=0.35, num_keep=100):
    tps, clas, p_scores = [], [], []
    classes, n_gts = LongTensor(range(n_classes)),torch.zeros(n_classes).long()
    with torch.no_grad():
        for input,target in progress_bar(dl):
            output = model(input)
            for i in range(target[0].size(0)):
                bbox_pred, preds, scores = get_predictions(output, i, detect_thresh)
                tgt_bbox, tgt_clas = unpad(target[0][i], target[1][i])
                if len(bbox_pred) != 0 and len(tgt_bbox) != 0:
                    ious = IoU_values(bbox_pred, tgt_bbox)
                    max_iou, matches = ious.max(1)
                    detected = []
                    for i in range_of(preds):
                        if max_iou[i] >= iou_thresh and matches[i] not in detected and tgt_clas[matches[i]] == preds[i]:
                            detected.append(matches[i])
                            tps.append(1)
                        else: tps.append(0)
                    clas.append(preds.cpu())
                    p_scores.append(scores.cpu())
                n_gts += (tgt_clas.cpu()[:,None] == classes[None,:]).sum(0)
    tps, p_scores, clas = torch.tensor(tps), torch.cat(p_scores,0), torch.cat(clas,0)
    fps = 1-tps
    idx = p_scores.argsort(descending=True)
    tps, fps, clas = tps[idx], fps[idx], clas[idx]
    aps = []
    #return tps, clas
    for cls in range(n_classes):
        tps_cls, fps_cls = tps[clas==cls].float().cumsum(0), fps[clas==cls].float().cumsum(0)
        if tps_cls.numel() != 0 and tps_cls[-1] != 0:
            precision = tps_cls / (tps_cls + fps_cls + 1e-8)
            recall = tps_cls / (n_gts[cls] + 1e-8)
            aps.append(compute_ap(precision, recall))
        else: aps.append(0.)
    return aps

Does anyone know how I can get the total number of positive predictions, false positives and negatives count for the same?