{"record":{"id":"e5a23b5ea5cd3bff","repo":"tensorflow/models","slug":"the-masks-must-have-the-same-dimensions-e5a23b","errorCode":null,"errorMessage":"The masks must have the same dimensions.","messagePattern":"The masks must have the same dimensions\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"official/projects/waste_identification_ml/model_inference/postprocessing.py","lineNumber":295,"sourceCode":"  return score, box, combined_label\n\n\ndef calculate_iou(\n    mask1: np.ndarray, mask2: np.ndarray\n) -> Tuple[float, np.ndarray]:\n  \"\"\"Calculates the intersection over union (IoU) score for two masks.\n\n  Args:\n    mask1: The first mask.\n    mask2: The second mask.\n\n  Returns:\n    The IoU scorea and union of two masks.\n  \"\"\"\n\n  # Check if the masks have the same dimensions.\n  if mask1.shape != mask2.shape:\n    raise ValueError('The masks must have the same dimensions.')\n\n  intersection = np.logical_and(mask1, mask2)\n  union = np.logical_or(mask1, mask2)\n  iou_score = np.sum(intersection) / np.sum(union)\n  return iou_score, union\n\n\ndef find_similar_masks(\n    results_1: DetectionResult,\n    results_2: DetectionResult,\n    num_detections: int,\n    min_score_thresh: float,\n    category_indices: List[List[Any]],\n    category_index_combined: Dict[int, ItemDict],\n    area_threshold: float,\n    iou_threshold: float = 0.8,\n) -> Dict[str, np.ndarray]:\n  \"\"\"Aligns the masks of the detections in `results_1` and `results_2`.","sourceCodeStart":277,"sourceCodeEnd":313,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/projects/waste_identification_ml/model_inference/postprocessing.py#L277-L313","documentation":"Error \"The masks must have the same dimensions.\" thrown in tensorflow/models.","triggerScenarios":"Thrown at official/projects/waste_identification_ml/model_inference/postprocessing.py:295 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e006f5f0d534913e49c1f1dae87364039fa607e2","analyzedAt":"2026-08-24T14:09:15.576Z","schemaVersion":2},"datasetVersion":"2026-08-24T17:17:21.512Z"}