{"record":{"id":"bdfa4449a51a54d7","repo":"tensorflow/models","slug":"the-image-has-spatial-dimensions-s-but-the-mask-h","errorCode":null,"errorMessage":"The image has spatial dimensions %s but the mask has dimensions %s","messagePattern":"The image has spatial dimensions (.+?) but the mask has dimensions (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"official/vision/utils/object_detection/visualization_utils.py","lineNumber":669,"sourceCode":"\n  Args:\n    image: uint8 numpy array with shape (img_height, img_height, 3)\n    mask: a uint8 numpy array of shape (img_height, img_height) with values\n      between either 0 or 1.\n    color: color to draw the keypoints with. Default is red.\n    alpha: transparency value between 0 and 1. (default: 0.4)\n\n  Raises:\n    ValueError: On incorrect data type for image or masks.\n  \"\"\"\n  if image.dtype != np.uint8:\n    raise ValueError('`image` not of type np.uint8')\n  if mask.dtype != np.uint8:\n    raise ValueError('`mask` not of type np.uint8')\n  if np.any(np.logical_and(mask != 1, mask != 0)):\n    raise ValueError('`mask` elements should be in [0, 1]')\n  if image.shape[:2] != mask.shape:\n    raise ValueError('The image has spatial dimensions %s but the mask has '\n                     'dimensions %s' % (image.shape[:2], mask.shape))\n  rgb = ImageColor.getrgb(color)\n  pil_image = Image.fromarray(image)\n\n  solid_color = np.expand_dims(\n      np.ones_like(mask), axis=2) * np.reshape(list(rgb), [1, 1, 3])\n  pil_solid_color = Image.fromarray(np.uint8(solid_color)).convert('RGBA')\n  pil_mask = Image.fromarray(np.uint8(255.0 * alpha * mask)).convert('L')\n  pil_image = Image.composite(pil_solid_color, pil_image, pil_mask)\n  np.copyto(image, np.array(pil_image.convert('RGB')))\n\n\ndef visualize_boxes_and_labels_on_image_array(\n    image,\n    boxes,\n    classes,\n    scores,\n    category_index,","sourceCodeStart":651,"sourceCodeEnd":687,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/vision/utils/object_detection/visualization_utils.py#L651-L687","documentation":"Error \"The image has spatial dimensions %s but the mask has dimensions %s\" thrown in tensorflow/models.","triggerScenarios":"Thrown at official/vision/utils/object_detection/visualization_utils.py:669 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Resize the mask to the image's spatial dimensions before overlaying.","Ensure mask and image share the same height and width."],"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"}