{"record":{"id":"b5711a9085cf1d80","repo":"tensorflow/models","slug":"groundtruth-matting-map-must-have-only-1-layer-bu","errorCode":null,"errorMessage":"Groundtruth matting map must have only 1 layer, but got {} layers.","messagePattern":"Groundtruth matting map must have only 1 layer, but got (.+?) layers\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"official/vision/losses/segmentation_losses.py","lineNumber":89,"sourceCode":"\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.\n      logits = tf.image.resize(\n          logits, tf.shape(labels)[1:3], method=tf.image.ResizeMethod.BILINEAR)\n    else:\n      labels = tf.image.resize(","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/vision/losses/segmentation_losses.py#L71-L107","documentation":"Error \"Groundtruth matting map must have only 1 layer, but got {} layers.\" thrown in tensorflow/models.","triggerScenarios":"Thrown at official/vision/losses/segmentation_losses.py:89 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"}