1

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 2

0

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:

2
  • 1
    Yeah, I can get these but is there any way I can get this for each step? This is when we have stopped the training and freezer the model right? As in the screenshot I provided you get metrics after each epoch, and you get plots too on the tensorboard. Can we get something like that in TF Object Detection API. Aug 25, 2021 at 13:37
  • Oh i see, i misunderstood your problem
    – Tsuki
    Aug 26, 2021 at 10:47
0

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 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.