{"record":{"id":"3e9d28e171f85f5d","repo":"tensorflow/models","slug":"one-and-only-one-of-annotation-file-and-gt-data","errorCode":null,"errorMessage":"One and only one of `annotation_file` and `gt_dataset` needs to be specified.","messagePattern":"One and only one of `annotation_file` and `gt_dataset` needs to be specified\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"official/legacy/detection/evaluation/coco_utils.py","lineNumber":60,"sourceCode":"    1. Support string type image id.\n    2. Support loading the groundtruth dataset using the external annotation\n       dictionary.\n    3. Support loading the prediction results using the external annotation\n       dictionary.\n  \"\"\"\n\n  def __init__(self, eval_type='box', annotation_file=None, gt_dataset=None):\n    \"\"\"Instantiates a COCO-style API object.\n\n    Args:\n      eval_type: either 'box' or 'mask'.\n      annotation_file: a JSON file that stores annotations of the eval dataset.\n        This is required if `gt_dataset` is not provided.\n      gt_dataset: the groundtruth eval datatset in COCO API format.\n    \"\"\"\n    if ((annotation_file and gt_dataset) or\n        ((not annotation_file) and (not gt_dataset))):\n      raise ValueError('One and only one of `annotation_file` and `gt_dataset` '\n                       'needs to be specified.')\n\n    if eval_type not in ['box', 'mask']:\n      raise ValueError('The `eval_type` can only be either `box` or `mask`.')\n\n    coco.COCO.__init__(self, annotation_file=annotation_file)\n    self._eval_type = eval_type\n    if gt_dataset:\n      self.dataset = gt_dataset\n      self.createIndex()\n\n  def loadRes(self, predictions):\n    \"\"\"Loads result file and return a result api object.\n\n    Args:\n      predictions: a list of dictionary each representing an annotation in COCO\n        format. The required fields are `image_id`, `category_id`, `score`,\n        `bbox`, `segmentation`.","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/legacy/detection/evaluation/coco_utils.py#L42-L78","documentation":"Error \"One and only one of `annotation_file` and `gt_dataset` needs to be specified.\" thrown in tensorflow/models.","triggerScenarios":"Thrown at official/legacy/detection/evaluation/coco_utils.py:60 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"}