tensorflow/models · error · ValueError
The masks must have the same dimensions.
Error message
The masks must have the same dimensions.
What it means
Error "The masks must have the same dimensions." thrown in tensorflow/models.
Source
Thrown at official/projects/waste_identification_ml/model_inference/postprocessing.py:295
return score, box, combined_label
def calculate_iou(
mask1: np.ndarray, mask2: np.ndarray
) -> Tuple[float, np.ndarray]:
"""Calculates the intersection over union (IoU) score for two masks.
Args:
mask1: The first mask.
mask2: The second mask.
Returns:
The IoU scorea and union of two masks.
"""
# Check if the masks have the same dimensions.
if mask1.shape != mask2.shape:
raise ValueError('The masks must have the same dimensions.')
intersection = np.logical_and(mask1, mask2)
union = np.logical_or(mask1, mask2)
iou_score = np.sum(intersection) / np.sum(union)
return iou_score, union
def find_similar_masks(
results_1: DetectionResult,
results_2: DetectionResult,
num_detections: int,
min_score_thresh: float,
category_indices: List[List[Any]],
category_index_combined: Dict[int, ItemDict],
area_threshold: float,
iou_threshold: float = 0.8,
) -> Dict[str, np.ndarray]:
"""Aligns the masks of the detections in `results_1` and `results_2`.View on GitHub (pinned to e006f5f0d5)
When it happens
Trigger: Thrown at official/projects/waste_identification_ml/model_inference/postprocessing.py:295 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of tensorflow/models@e006f5f0d5 (2026-08-24).
Data as JSON: /api/errors/e5a23b5ea5cd3bff.
Report an issue: GitHub.