tensorflow/models · error · ValueError
Groundtruth matting map only supports 2 classes, but got {}
Error message
Groundtruth matting map only supports 2 classes, but got {} classes. What it means
Error "Groundtruth matting map only supports 2 classes, but got {} classes." thrown in tensorflow/models.
Source
Thrown at official/vision/losses/segmentation_losses.py:85
labels: A tensor in shape (batch_size, height, width, num_layers), which
is the label masks of the ground truth. The num_layers can be > 1 if the
pixels are labeled as multiple classes.
**kwargs: additional keyword arguments.
Returns:
A 0-D float which stores the overall loss of the batch.
"""
_, height, width, num_classes = logits.get_shape().as_list()
output_dtype = logits.dtype
num_layers = labels.get_shape().as_list()[-1]
if not self._use_binary_cross_entropy:
if num_layers > 1:
raise ValueError(
'Groundtruth mask must have only 1 layer if using categorical'
'cross entropy, but got {} layers.'.format(num_layers))
if self._gt_is_matting_map:
if num_classes != 2:
raise ValueError(
'Groundtruth matting map only supports 2 classes, but got {} '
'classes.'.format(num_classes))
if num_layers > 1:
raise ValueError(
'Groundtruth matting map must have only 1 layer, but got {} '
'layers.'.format(num_layers))
class_weights = (
self._class_weights if self._class_weights else [1] * num_classes)
if num_classes != len(class_weights):
raise ValueError(
'Length of class_weights should be {}'.format(num_classes))
class_weights = tf.constant(class_weights, dtype=output_dtype)
if not self._gt_is_matting_map:
labels = tf.cast(labels, tf.int32)
if self._use_groundtruth_dimension:
# TODO(arashwan): Test using align corners to match deeplab alignment.View on GitHub (pinned to e006f5f0d5)
When it happens
Trigger: Thrown at official/vision/losses/segmentation_losses.py:85 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of tensorflow/models@e006f5f0d5 (2026-08-24).
Data as JSON: /api/errors/3f602f1472d7cef4.
Report an issue: GitHub.