WZMIAOMIAO/deep-learning-for-image-processing · error · ValueError

No proposal boxes available for one of the images during tra

Error message

No proposal boxes available for one of the images during training

What it means

Matcher.__call__ raises this when match_quality_matrix is empty but the empty dimension is the proposals axis (shape[1] == 0, i.e. shape[0] > 0): ground-truth boxes exist but no proposals were generated for one of the images during training. Without proposals there is nothing to match against, so training cannot proceed.

Source

Thrown at pytorch_object_detection/mask_rcnn/network_files/det_utils.py:321

        计算anchors与每个gtboxes匹配的iou最大值,并记录索引,
        iou<low_threshold索引值为-1, low_threshold<=iou<high_threshold索引值为-2
        Args:
            match_quality_matrix (Tensor[float]): an MxN tensor, containing the
            pairwise quality between M ground-truth elements and N predicted elements.

        Returns:
            matches (Tensor[int64]): an N tensor where N[i] is a matched gt in
            [0, M - 1] or a negative value indicating that prediction i could not
            be matched.
        """
        if match_quality_matrix.numel() == 0:
            # empty targets or proposals not supported during training
            if match_quality_matrix.shape[0] == 0:
                raise ValueError(
                    "No ground-truth boxes available for one of the images "
                    "during training")
            else:
                raise ValueError(
                    "No proposal boxes available for one of the images "
                    "during training")

        # match_quality_matrix is M (gt) x N (predicted)
        # Max over gt elements (dim 0) to find best gt candidate for each prediction
        # M x N 的每一列代表一个anchors与所有gt的匹配iou值
        # matched_vals代表每列的最大值,即每个anchors与所有gt匹配的最大iou值
        # matches对应最大值所在的索引
        matched_vals, matches = match_quality_matrix.max(dim=0)  # the dimension to reduce.
        if self.allow_low_quality_matches:
            all_matches = matches.clone()
        else:
            all_matches = None

        # Assign candidate matches with low quality to negative (unassigned) values
        # 计算iou小于low_threshold的索引
        below_low_threshold = matched_vals < self.low_threshold
        # 计算iou在low_threshold与high_threshold之间的索引值

View on GitHub (pinned to 1ec3fe6f37)

Solutions

  1. Increase rpn_pre_nms_top_n_test/rpn_post_nms_top_n (and training equivalents) so at least some proposals survive per image
  2. Verify the RPN head outputs sane objectness logits; debug feature maps for NaNs or all-negative scores
  3. Check image sizes and anchor generator settings so anchors actually fit the input images

Example fix

// before
model = fasterrcnn_resnet50_fpn(pretrained=False, rpn_post_nms_top_n_train=0)
// after
model = fasterrcnn_resnet50_fpn(pretrained=False, rpn_pre_nms_top_n_train=2000, rpn_post_nms_top_n_train=2000)
Defensive patterns

Strategy: validation

Validate before calling

assert model.rpn._pre_nms_top_n['training'] > 0 and model.rpn._post_nms_top_n['training'] > 0, 'RPN top-N must allow proposals'

Try / catch

try:
    losses = model(images, targets)
except ValueError as e:
    if 'No proposal boxes' in str(e):
        inspect_rpn_outputs(images)  # debug objectness/anchors for the offending image
    raise

Prevention

When it happens

Trigger: Training Faster/Mask R-CNN where the RPN produced zero proposals for an image (e.g. all objectness scores below threshold, rpn_pre_nms_top_n/rpn_post_nms_top_n set to 0 or too small, or degenerate feature maps), leading to match_quality_matrix with 0 columns.

Common situations: Misconfigured RPN top-N parameters; a broken backbone outputting all-negative objectness; very small images where anchors are all invalid; custom RPN modifications suppressing all proposals.

Related errors


AI-assisted analysis of WZMIAOMIAO/deep-learning-for-image-processing@1ec3fe6f37 (2026-08-30). Data as JSON: /api/errors/52019f93eece6ddf. Report an issue: GitHub.