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

The sibling case in Matcher.__call__: match_quality_matrix has zero columns (N=0) meaning no proposals/anchors were produced for an image, so raise 'No proposal boxes available...'. Assignment between GT and proposals is impossible with zero proposals, hence training aborts with this ValueError.

Source

Thrown at pytorch_object_detection/faster_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 input image size or check transforms — images smaller than the anchor stride produce no valid anchors.
  2. Verify rpn_anchor_generator and feature-map sizes (feature maps must be large enough for anchors).
  3. Check min_size / RPN pre/post-nms_top_n settings aren't filtering all proposals.
  4. Log len(proposals) per image to find which images yield zero proposals.
  5. Ensure normalized/degenerate boxes aren't collapsing after clip_to_image/remove_small_boxes.

Example fix

# before
images, targets = transforms(images, targets)  # tiny images shrink feature maps to zero anchors
# after
if any(img.shape[-1] < 32 or img.shape[-2] < 32 for img in images):
    images = [F.interpolate(img.unsqueeze(0), size=(min(800, max(img.shape[-2], 32)), min(1333, max(img.shape[-1], 32)))).squeeze(0) for img in images]
Defensive patterns

Strategy: validation

Validate before calling

assert min(img.shape[-2] for img in images) >= 32 and min(img.shape[-1] for img in images) >= 32, "image too small: anchors may be empty"

Type guard

def has_valid_proposals(proposals) -> bool:
    return all(p.shape[0] > 0 for p in proposals)

Try / catch

try:
    loss_dict = model(images, targets)
except ValueError as e:
    if 'proposal' in str(e):
        print('Zero proposals: enlarge input image or fix anchor config'); continue
    raise

Prevention

When it happens

Trigger: RPN generates no proposals/anchors for an image — typically all anchors discarded (e.g. tiny images smaller than anchor base sizes, degenerate boxes after clipping), or an upstream filter empties the proposal list during training.

Common situations: Extremely small input images, wrong min_size/anchor generator config, custom backbones producing tiny feature maps, or proposal filtering removing everything before the matcher.

Related errors


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