Get coco performance metric while training tensorflow object detection api

Viewed 217

I want to know how good my model is while training i.e. like in the following image, I was training YoloV5 using Pytorch and it prints mAP, Precision, Recall metric with each epoch. Can we do that with TensorFlow object detection API?

enter image description here

2 Answers

Yes. While training, tf object detection api gives you classification_loss, localization_loss ,regularization_loss etc. Evaluating the trained model gives you more details such as the loss metrics i said before, recall,precision, mAP, mAP.5 mAP.75 and more. Here is an example:

I'm not entirely sure how to make this happen while training, perhaps if you created your own training loop you can incorporate calculating the MAP scores. But once we have a model, we can use a function like this to determine MAP for a dataset.

!git clone https://github.com/matterport/Mask_RCNN.git
from mrcnn.utils import compute_ap
from mrcnn.model import load_image_gt
from mrcnn.model import mold_image
from numpy import zeros, asarray, expand_dims, mean

def evaluate_model(dataset, model, cfg):
    APs = list()
    for image_id in dataset.image_ids:
        # load image, bounding boxes and masks for the image id
        image, image_meta, gt_class_id, gt_bbox, gt_mask = load_image_gt(dataset, cfg, image_id, use_mini_mask=False)
        # convert pixel values (e.g. center)
        scaled_image = mold_image(image, cfg)
        # convert image into one sample
        sample = expand_dims(scaled_image, 0)
        # make prediction
        yhat = model.detect(sample, verbose=0)
        # extract results for first sample
        r = yhat[0]
        # calculate statistics, including AP
        AP, _, _, _ = compute_ap(gt_bbox, gt_class_id, gt_mask, r["rois"], r["class_ids"], r["scores"], r['masks'])
        # store
        APs.append(AP)
    # calculate the mean AP across all images
    mAP = mean(APs)
    return mAP 
Related