Mask_rcnn: Insepct model, problem with compute AP

Created on 21 Sep 2018  ·  7Comments  ·  Source: matterport/Mask_RCNN

Hello, I wanted to draw precisionrecall graph, but I have an error.

ValueError                                Traceback (most recent call last)
<ipython-input-53-046d0b607c9e> in <module>()
      2 from mrcnn import utils
      3 AP, precisions, recalls, overlaps = utils.compute_ap(gt_bbox, gt_class_id, gt_mask,
----> 4                                           r['rois'], r['class_ids'], r['scores'], r['masks'])
      5 visualize.plot_precision_recall(AP, precisions, recalls)

~/tensorflow_related/Mask_RCNN/mrcnn/utils.py in compute_ap(gt_boxes, gt_class_ids, gt_masks, pred_boxes, pred_class_ids, pred_scores, pred_masks, iou_threshold)
    733         gt_boxes, gt_class_ids, gt_masks,
    734         pred_boxes, pred_class_ids, pred_scores, pred_masks,
--> 735         iou_threshold)
    736 
    737     # Compute precision and recall at each prediction box step

~/tensorflow_related/Mask_RCNN/mrcnn/utils.py in compute_matches(gt_boxes, gt_class_ids, gt_masks, pred_boxes, pred_class_ids, pred_scores, pred_masks, iou_threshold, score_threshold)
    685 
    686     # Compute IoU overlaps [pred_masks, gt_masks]
--> 687     overlaps = compute_overlaps_masks(pred_masks, gt_masks)
    688 
    689     # Loop through predictions and find matching ground truth boxes

~/tensorflow_related/Mask_RCNN/mrcnn/utils.py in compute_overlaps_masks(masks1, masks2)
    107 
    108     # intersections and union
--> 109     intersections = np.dot(masks1.T, masks2)
    110     union = area1[:, None] + area2[None, :] - intersections
    111     overlaps = intersections / union

ValueError: shapes (1,589824) and (2304,1) not aligned: 589824 (dim 1) != 2304 (dim 0)

The notebook lines are:

AP, precisions, recalls, overlaps = utils.compute_ap(gt_bbox, gt_class_id, gt_mask,
                                          r['rois'], r['class_ids'], r['scores'], r['masks'])
visualize.plot_precision_recall(AP, precisions, recalls)

My config, images are 768x768

BACKBONE                       resnet101
BACKBONE_STRIDES               [4, 8, 16, 32, 64]
BATCH_SIZE                     1
BBOX_STD_DEV                   [0.1 0.1 0.2 0.2]
DETECTION_MAX_INSTANCES        100
DETECTION_MIN_CONFIDENCE       0.7
DETECTION_NMS_THRESHOLD        0.3
GPU_COUNT                      1
GRADIENT_CLIP_NORM             5.0
IMAGES_PER_GPU                 1
IMAGE_MAX_DIM                  768
IMAGE_META_SIZE                14
IMAGE_MIN_DIM                  768
IMAGE_MIN_SCALE                0
IMAGE_RESIZE_MODE              pad64
IMAGE_SHAPE                    [768 768   3]
LEARNING_MOMENTUM              0.9
LEARNING_RATE                  0.001
LOSS_WEIGHTS                   {'mrcnn_bbox_loss': 1.0, 'mrcnn_class_loss': 1.0, 'rpn_bbox_loss': 1.0, 'mrcnn_mask_loss': 1.0, 'rpn_class_loss': 1.0}
MASK_POOL_SIZE                 14
MASK_SHAPE                     [28, 28]
MAX_GT_INSTANCES               100
MEAN_PIXEL                     [123.7 116.8 103.9]
MINI_MASK_SHAPE                (56, 56)
NUM_CLASSES                    2
POOL_SIZE                      7
POST_NMS_ROIS_INFERENCE        1000
POST_NMS_ROIS_TRAINING         2000
ROI_POSITIVE_RATIO             0.33
RPN_ANCHOR_RATIOS              [0.5, 1, 2]
RPN_ANCHOR_SCALES              (32, 64, 96, 128, 160)
RPN_ANCHOR_STRIDE              1
RPN_BBOX_STD_DEV               [0.1 0.1 0.2 0.2]
RPN_NMS_THRESHOLD              0.7
RPN_TRAIN_ANCHORS_PER_IMAGE    256
STEPS_PER_EPOCH                400
TRAIN_BN                       False
TRAIN_ROIS_PER_IMAGE           512
USE_MINI_MASK                  True
USE_RPN_ROIS                   True
VALIDATION_STEPS               100
WEIGHT_DECAY                   0.0001

Most helpful comment

@kesaroid hey, did you solve it? because i have the same error?
how?

All 7 comments

This isn't an error related to the ap or plot functions. It is probably the prediction isn't working for you, Check that the prediction and gt have the same shape for a starter. To cross check I just tested both methods and they work just fine. here is the outcome from one image.
image

Hi @AloshkaD , I am getting the right predictions, but instead of PR curve showing 1, It is showing 0. How do I change this?

@kesaroid hey, did you solve it? because i have the same error?
how?

您好,我想绘制precision recall图,但是出现错误。

ValueError                                Traceback (most recent call last)
<ipython-input-53-046d0b607c9e> in <module>()
      2 from mrcnn import utils
      3 AP, precisions, recalls, overlaps = utils.compute_ap(gt_bbox, gt_class_id, gt_mask,
----> 4                                           r['rois'], r['class_ids'], r['scores'], r['masks'])
      5 visualize.plot_precision_recall(AP, precisions, recalls)

~/tensorflow_related/Mask_RCNN/mrcnn/utils.py in compute_ap(gt_boxes, gt_class_ids, gt_masks, pred_boxes, pred_class_ids, pred_scores, pred_masks, iou_threshold)
    733         gt_boxes, gt_class_ids, gt_masks,
    734         pred_boxes, pred_class_ids, pred_scores, pred_masks,
--> 735         iou_threshold)
    736 
    737     # Compute precision and recall at each prediction box step

~/tensorflow_related/Mask_RCNN/mrcnn/utils.py in compute_matches(gt_boxes, gt_class_ids, gt_masks, pred_boxes, pred_class_ids, pred_scores, pred_masks, iou_threshold, score_threshold)
    685 
    686     # Compute IoU overlaps [pred_masks, gt_masks]
--> 687     overlaps = compute_overlaps_masks(pred_masks, gt_masks)
    688 
    689     # Loop through predictions and find matching ground truth boxes

~/tensorflow_related/Mask_RCNN/mrcnn/utils.py in compute_overlaps_masks(masks1, masks2)
    107 
    108     # intersections and union
--> 109     intersections = np.dot(masks1.T, masks2)
    110     union = area1[:, None] + area2[None, :] - intersections
    111     overlaps = intersections / union

ValueError: shapes (1,589824) and (2304,1) not aligned: 589824 (dim 1) != 2304 (dim 0)

笔记本行是:

AP, precisions, recalls, overlaps = utils.compute_ap(gt_bbox, gt_class_id, gt_mask,
                                          r['rois'], r['class_ids'], r['scores'], r['masks'])
visualize.plot_precision_recall(AP, precisions, recalls)

我的配置是768x768

BACKBONE                       resnet101
BACKBONE_STRIDES               [4, 8, 16, 32, 64]
BATCH_SIZE                     1
BBOX_STD_DEV                   [0.1 0.1 0.2 0.2]
DETECTION_MAX_INSTANCES        100
DETECTION_MIN_CONFIDENCE       0.7
DETECTION_NMS_THRESHOLD        0.3
GPU_COUNT                      1
GRADIENT_CLIP_NORM             5.0
IMAGES_PER_GPU                 1
IMAGE_MAX_DIM                  768
IMAGE_META_SIZE                14
IMAGE_MIN_DIM                  768
IMAGE_MIN_SCALE                0
IMAGE_RESIZE_MODE              pad64
IMAGE_SHAPE                    [768 768   3]
LEARNING_MOMENTUM              0.9
LEARNING_RATE                  0.001
LOSS_WEIGHTS                   {'mrcnn_bbox_loss': 1.0, 'mrcnn_class_loss': 1.0, 'rpn_bbox_loss': 1.0, 'mrcnn_mask_loss': 1.0, 'rpn_class_loss': 1.0}
MASK_POOL_SIZE                 14
MASK_SHAPE                     [28, 28]
MAX_GT_INSTANCES               100
MEAN_PIXEL                     [123.7 116.8 103.9]
MINI_MASK_SHAPE                (56, 56)
NUM_CLASSES                    2
POOL_SIZE                      7
POST_NMS_ROIS_INFERENCE        1000
POST_NMS_ROIS_TRAINING         2000
ROI_POSITIVE_RATIO             0.33
RPN_ANCHOR_RATIOS              [0.5, 1, 2]
RPN_ANCHOR_SCALES              (32, 64, 96, 128, 160)
RPN_ANCHOR_STRIDE              1
RPN_BBOX_STD_DEV               [0.1 0.1 0.2 0.2]
RPN_NMS_THRESHOLD              0.7
RPN_TRAIN_ANCHORS_PER_IMAGE    256
STEPS_PER_EPOCH                400
TRAIN_BN                       False
TRAIN_ROIS_PER_IMAGE           512
USE_MINI_MASK                  True
USE_RPN_ROIS                   True
VALIDATION_STEPS               100
WEIGHT_DECAY                   0.0001

I have encountered the same problem. Have you solved it?

@kesaroid hey, did you solve it? because i have the same error?
how?

I got stuck with the same issue when working on my datasets. I appreciate if you would like to share your experience to solve it. Thanks.

This isn't an error related to the ap or plot functions. It is probably the prediction isn't working for you, Check that the prediction and gt have the same shape for a starter. To cross check I just tested both methods and they work just fine. here is the outcome from one image.
image

I use utils.compute_ap get the precisions and recalls, but precision always be 1, my dataset_val has 10 picture.
I don't know what to do, can anyone help me?

Would you tell me how to change the SHAP SIZE?

have u solved this problem. i am getting this error too

Was this page helpful?
0 / 5 - 0 ratings

Related issues

canerozer picture canerozer  ·  3Comments

Mabinogiysk picture Mabinogiysk  ·  3Comments

ziyigogogo picture ziyigogogo  ·  3Comments

PaulChongPeng picture PaulChongPeng  ·  4Comments

techjjun picture techjjun  ·  4Comments