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

Same Matcher.__call__ guard as the empty ground-truth case, but the else branch: the IoU matrix is empty because there are zero columns, i.e. no proposal/anchor boxes were produced for one image during training. RetinaNet normally generates tens of thousands of anchors, so this usually means anchors were entirely filtered or input boxes were degenerate before anchor sampling.

Source

Thrown at pytorch_object_detection/retinaNet/network_files/det_utils.py:320

        计算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. Check input image sizes; ensure min/max resize keeps spatial dimensions large enough to generate anchors.
  2. Inspect the transform pipeline (GeneralizedRCNNTransform) so images are not resized to degenerate shapes.
  3. If supplying custom anchors/proposals, verify each image contributes at least one box.
  4. Confirm GT boxes are valid (non-degenerate) so downstream filtering does not wipe out all candidates.

Example fix

// before
features = self.backbone(images.tensors)  # images may be tiny after bad resize
// after
assert all(min(s) >= 32 for s in images.tensors.shape[-2:]), "image too small to generate anchors"
features = self.backbone(images.tensors)
Defensive patterns

Strategy: validation

Validate before calling

assert images.tensors.shape[-1] >= 32 and images.tensors.shape[-2] >= 32, "image too small for anchor generation"

Type guard

def anchors_available(model, images) -> bool:
    features = model.backbone(images.tensors)
    return any(f.shape[-1] > 0 and f.shape[-2] > 0 for f in (features.values() if isinstance(features, dict) else [features]))

Try / catch

try:
    loss_dict = model(images, targets)
except ValueError as e:
    if "No proposal boxes" in str(e):
        log.warning("no anchors/proposals for an image; check sizes", exc_info=True)
        continue
    raise

Prevention

When it happens

Trigger: Training where proposed_boxes/anchors list is empty for an image (match_quality_matrix.shape[1]==0, shape[0]>0): typically downstream of all anchors being discarded by size/cropping filters after extreme resizes, or an empty proposals tensor passed to assign_targets_to_proposals.

Common situations: Extreme image sizes (e.g. tiny images after resize producing zero valid anchors); custom backbones/FPN changes dropping all feature-map anchors; feeding pre-computed proposals that ended up empty; corrupted boxes causing earlier filtering to remove everything.

Related errors


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