tensorflow/models · error · ValueError

Attribute {head.name} not found in label targets.

Error message

Attribute {head.name} not found in label targets.

What it means

Error "Attribute {head.name} not found in label targets." thrown in tensorflow/models.

Source

Thrown at official/vision/tasks/retinanet.py:174

                           outputs: Mapping[str, Any],
                           labels: Mapping[str, Any],
                           box_sample_weight: tf.Tensor) -> float:
    """Computes attribute loss.

    Args:
      attribute_heads: a list of attribute head configs.
      outputs: RetinaNet model outputs.
      labels: RetinaNet labels.
      box_sample_weight: normalized bounding box sample weights.

    Returns:
      Attribute loss of all attribute heads.
    """
    params = self.task_config
    attribute_loss = 0.0
    for head in attribute_heads:
      if head.name not in labels['attribute_targets']:
        raise ValueError(f'Attribute {head.name} not found in label targets.')
      if head.name not in outputs['attribute_outputs']:
        raise ValueError(f'Attribute {head.name} not found in model outputs.')

      if head.type == 'regression':
        y_true_att = loss_utils.multi_level_flatten(
            labels['attribute_targets'][head.name], last_dim=head.size
        )
        y_pred_att = loss_utils.multi_level_flatten(
            outputs['attribute_outputs'][head.name], last_dim=head.size
        )
        att_loss_fn = tf_keras.losses.Huber(
            1.0, reduction=tf_keras.losses.Reduction.SUM)
        att_loss = att_loss_fn(
            y_true=y_true_att,
            y_pred=y_pred_att,
            sample_weight=box_sample_weight)
      elif head.type == 'classification':
        y_true_att = loss_utils.multi_level_flatten(

View on GitHub (pinned to e006f5f0d5)

Solutions

  1. Add the attribute head's target under the head name key in the label targets dict.
  2. Ensure the input pipeline emits the attribute labels keyed by head.name.

When it happens

Trigger: Thrown at official/vision/tasks/retinanet.py:174 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/a9e7d9eb857f2726. Report an issue: GitHub.