{"record":{"id":"deb7507adf36de55","repo":"tensorflow/models","slug":"mask-not-of-type-np-uint8","errorCode":null,"errorMessage":"`mask` not of type np.uint8","messagePattern":"`mask` not of type np\\.uint8","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"official/vision/utils/object_detection/visualization_utils.py","lineNumber":665,"sourceCode":"\n\ndef draw_mask_on_image_array(image, mask, color='red', alpha=0.4):\n  \"\"\"Draws mask on an image.\n\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,","sourceCodeStart":647,"sourceCodeEnd":683,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/vision/utils/object_detection/visualization_utils.py#L647-L683","documentation":"Error \"`mask` not of type np.uint8\" thrown in tensorflow/models.","triggerScenarios":"Thrown at official/vision/utils/object_detection/visualization_utils.py:665 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Convert the mask to np.uint8 before visualization.","Use mask.astype(np.uint8) after thresholding or scaling."],"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"}