{"record":{"id":"52019f93eece6ddf","repo":"WZMIAOMIAO/deep-learning-for-image-processing","slug":"no-proposal-boxes-available-for-one-of-the-images-52019f","errorCode":null,"errorMessage":"No proposal boxes available for one of the images during training","messagePattern":"No proposal boxes available for one of the images during training","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"pytorch_object_detection/mask_rcnn/network_files/det_utils.py","lineNumber":321,"sourceCode":"        计算anchors与每个gtboxes匹配的iou最大值，并记录索引，\n        iou<low_threshold索引值为-1， low_threshold<=iou<high_threshold索引值为-2\n        Args:\n            match_quality_matrix (Tensor[float]): an MxN tensor, containing the\n            pairwise quality between M ground-truth elements and N predicted elements.\n\n        Returns:\n            matches (Tensor[int64]): an N tensor where N[i] is a matched gt in\n            [0, M - 1] or a negative value indicating that prediction i could not\n            be matched.\n        \"\"\"\n        if match_quality_matrix.numel() == 0:\n            # empty targets or proposals not supported during training\n            if match_quality_matrix.shape[0] == 0:\n                raise ValueError(\n                    \"No ground-truth boxes available for one of the images \"\n                    \"during training\")\n            else:\n                raise ValueError(\n                    \"No proposal boxes available for one of the images \"\n                    \"during training\")\n\n        # match_quality_matrix is M (gt) x N (predicted)\n        # Max over gt elements (dim 0) to find best gt candidate for each prediction\n        # M x N 的每一列代表一个anchors与所有gt的匹配iou值\n        # matched_vals代表每列的最大值，即每个anchors与所有gt匹配的最大iou值\n        # matches对应最大值所在的索引\n        matched_vals, matches = match_quality_matrix.max(dim=0)  # the dimension to reduce.\n        if self.allow_low_quality_matches:\n            all_matches = matches.clone()\n        else:\n            all_matches = None\n\n        # Assign candidate matches with low quality to negative (unassigned) values\n        # 计算iou小于low_threshold的索引\n        below_low_threshold = matched_vals < self.low_threshold\n        # 计算iou在low_threshold与high_threshold之间的索引值","sourceCodeStart":303,"sourceCodeEnd":339,"githubUrl":"https://github.com/WZMIAOMIAO/deep-learning-for-image-processing/blob/1ec3fe6f374fc9969973a61f819de25658595afa/pytorch_object_detection/mask_rcnn/network_files/det_utils.py#L303-L339","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Increase rpn_pre_nms_top_n_test/rpn_post_nms_top_n (and training equivalents) so at least some proposals survive per image","Verify the RPN head outputs sane objectness logits; debug feature maps for NaNs or all-negative scores","Check image sizes and anchor generator settings so anchors actually fit the input images"],"exampleFix":"// before\nmodel = fasterrcnn_resnet50_fpn(pretrained=False, rpn_post_nms_top_n_train=0)\n// after\nmodel = fasterrcnn_resnet50_fpn(pretrained=False, rpn_pre_nms_top_n_train=2000, rpn_post_nms_top_n_train=2000)","handlingStrategy":"validation","validationCode":"assert model.rpn._pre_nms_top_n['training'] > 0 and model.rpn._post_nms_top_n['training'] > 0, 'RPN top-N must allow proposals'","typeGuard":null,"tryCatchPattern":"try:\n    losses = model(images, targets)\nexcept ValueError as e:\n    if 'No proposal boxes' in str(e):\n        inspect_rpn_outputs(images)  # debug objectness/anchors for the offending image\n    raise","preventionTips":["Keep rpn_pre/post_nms_top_n training values at sane defaults (e.g. 2000)","Sanity-check RPN objectness distribution after the first training step","Avoid tiny images or anchor configs that produce zero valid anchors"],"tags":["pytorch","training","rpn"],"backgroundTag":"empty-proposal-boxes","analyzedSha":"1ec3fe6f374fc9969973a61f819de25658595afa","analyzedAt":"2026-08-30T09:19:11.901Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}