tensorflow/models · error · ValueError

The `eval_type` can only be either `box` or `mask`.

Error message

The `eval_type` can only be either `box` or `mask`.

What it means

Enum guard in the COCO wrapper constructor: eval_type must be exactly 'box' or 'mask', but another value was supplied. Any other string (or typo like 'bbox' or 'Mask') leaves the evaluator unable to decide which COCO evaluation subtype to run.

Solutions

  1. Pass eval_type='box' for bounding-box evaluation
  2. Pass eval_type='mask' for instance-segmentation evaluation
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at official/legacy/detection/evaluation/coco_utils.py:64 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/3c9f13a059442c93. Report an issue: GitHub.

Appendix: source

Thrown at official/legacy/detection/evaluation/coco_utils.py:64

       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 groundtruth 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`.

    Returns:
      res: result COCO api object.

View on GitHub (pinned to e006f5f0d5)