tensorflow/models · error · ValueError

One and only one of `annotation_file` and `gt_dataset` needs

Error message

One and only one of `annotation_file` and `gt_dataset` needs to be specified.

What it means

Error "One and only one of `annotation_file` and `gt_dataset` needs to be specified." thrown in tensorflow/models.

Source

Thrown at official/vision/evaluation/coco_utils.py:57

    1. Support string type image id.
    2. Support loading the ground-truth dataset using the external annotation
       dictionary.
    3. Support loading the prediction results using the external annotation
       dictionary.
  """

  def __init__(self, eval_type='box', annotation_file=None, gt_dataset=None):
    """Instantiates a COCO-style API object.

    Args:
      eval_type: either 'box' or 'mask'.
      annotation_file: a JSON file that stores annotations of the eval dataset.
        This is required if `gt_dataset` is not provided.
      gt_dataset: the ground-truth eval datatset in COCO API format.
    """
    if ((annotation_file and gt_dataset) or
        ((not annotation_file) and (not gt_dataset))):
      raise ValueError('One and only one of `annotation_file` and `gt_dataset` '
                       'needs to be specified.')

    if eval_type not in ['box', 'mask']:
      raise ValueError('The `eval_type` can only be either `box` or `mask`.')

    coco.COCO.__init__(self, annotation_file=annotation_file)
    self._eval_type = eval_type
    if gt_dataset:
      self.dataset = gt_dataset
      self.createIndex()

  def loadRes(self, predictions):
    """Loads result file and return a result api object.

    Args:
      predictions: a list of dictionary each representing an annotation in COCO
        format. The required fields are `image_id`, `category_id`, `score`,
        `bbox`, `segmentation`.

View on GitHub (pinned to e006f5f0d5)

When it happens

Trigger: Thrown at official/vision/evaluation/coco_utils.py:57 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/eda9c90b2fbfd853. Report an issue: GitHub.