{"record":{"id":"3f602f1472d7cef4","repo":"tensorflow/models","slug":"groundtruth-matting-map-only-supports-2-classes-b","errorCode":null,"errorMessage":"Groundtruth matting map only supports 2 classes, but got {} classes.","messagePattern":"Groundtruth matting map only supports 2 classes, but got (.+?) classes\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"official/vision/losses/segmentation_losses.py","lineNumber":85,"sourceCode":"      labels: A tensor in shape (batch_size, height, width, num_layers), which\n        is the label masks of the ground truth. The num_layers can be > 1 if the\n        pixels are labeled as multiple classes.\n      **kwargs: additional keyword arguments.\n\n    Returns:\n       A 0-D float which stores the overall loss of the batch.\n    \"\"\"\n    _, height, width, num_classes = logits.get_shape().as_list()\n    output_dtype = logits.dtype\n    num_layers = labels.get_shape().as_list()[-1]\n    if not self._use_binary_cross_entropy:\n      if num_layers > 1:\n        raise ValueError(\n            'Groundtruth mask must have only 1 layer if using categorical'\n            'cross entropy, but got {} layers.'.format(num_layers))\n    if self._gt_is_matting_map:\n      if num_classes != 2:\n        raise ValueError(\n            'Groundtruth matting map only supports 2 classes, but got {} '\n            'classes.'.format(num_classes))\n      if num_layers > 1:\n        raise ValueError(\n            'Groundtruth matting map must have only 1 layer, but got {} '\n            'layers.'.format(num_layers))\n\n    class_weights = (\n        self._class_weights if self._class_weights else [1] * num_classes)\n    if num_classes != len(class_weights):\n      raise ValueError(\n          'Length of class_weights should be {}'.format(num_classes))\n    class_weights = tf.constant(class_weights, dtype=output_dtype)\n\n    if not self._gt_is_matting_map:\n      labels = tf.cast(labels, tf.int32)\n    if self._use_groundtruth_dimension:\n      # TODO(arashwan): Test using align corners to match deeplab alignment.","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/vision/losses/segmentation_losses.py#L67-L103","documentation":"Error \"Groundtruth matting map only supports 2 classes, but got {} classes.\" thrown in tensorflow/models.","triggerScenarios":"Thrown at official/vision/losses/segmentation_losses.py:85 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"}