{"record":{"id":"fa6bb5e80ff8cebe","repo":"roboflow/supervision","slug":"the-provided-transformers-results-do-not-contain-a","errorCode":null,"errorMessage":"The provided Transformers results do not contain any valid fields. Expected fields are 'boxes', 'masks', 'segments_info' or 'segmentation'.","messagePattern":"The provided Transformers results do not contain any valid fields\\. Expected fields are 'boxes', 'masks', 'segments_info' or 'segmentation'\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/supervision/detection/core.py","lineNumber":629,"sourceCode":"                **process_transformers_v5_segmentation_result(\n                    transformers_results, id2label\n                )\n            )\n\n        if \"masks\" in transformers_results or \"png_string\" in transformers_results:\n            return cls(\n                **process_transformers_v4_segmentation_result(\n                    transformers_results, id2label\n                )\n            )\n\n        if \"boxes\" in transformers_results:\n            return cls(\n                **process_transformers_detection_result(transformers_results, id2label)\n            )\n\n        else:\n            raise ValueError(\n                \"The provided Transformers results do not contain any valid fields.\"\n                \" Expected fields are 'boxes', 'masks', 'segments_info' or\"\n                \" 'segmentation'.\"\n            )\n\n    @classmethod\n    def from_detectron2(cls, detectron2_results: Any) -> Detections:\n        \"\"\"\n        Create a Detections object from the\n        [Detectron2](https://github.com/facebookresearch/detectron2) inference result.\n\n        Args:\n            detectron2_results: The output of a\n                Detectron2 model containing instances with prediction data.\n\n        Returns:\n            A Detections object containing the bounding boxes,\n                class IDs, and confidences of the predictions.","sourceCodeStart":611,"sourceCodeEnd":647,"githubUrl":"https://github.com/roboflow/supervision/blob/7f254d9784d4c37e0f03cd89ddee164c8db099c0/src/supervision/detection/core.py#L611-L647","documentation":"Detections.from_transformers dispatches on the keys present in the HF Transformers output dict: 'masks'/'segments_info' route to segmentation processing, 'boxes' to detection processing. If none of those keys exist, the result cannot be interpreted and this ValueError is raised.","triggerScenarios":"Calling from_transformers(results, id2label) where results is a dict lacking 'boxes', 'masks', 'segments_info', and 'segmentation' — e.g. passing raw model tensors instead of post-processor output, an empty dict, or output from a task head that produces none of these fields.","commonSituations":"Skipping the HF object-detection/segmentation post-processor (e.g. Owlv2ImageProcessor.post_process_object_detection or DetrImageProcessor) and passing model(**inputs) logits directly; transformers version changes renaming output keys; passing image-classification or zero-shot pipeline outputs.","solutions":["Run the model output through the appropriate processor post-process step first, then pass that list element to from_transformers (e.g. results = processor.post_process_object_detection(outputs, target_sizes=...)[0]).","Inspect the keys you are passing: print(results.keys()) and confirm 'boxes' (detection) or 'masks'/'segments_info' (segmentation) is present.","If building the dict manually, include the 'boxes' key with the expected box tensor format."],"exampleFix":"# before\nwith torch.no_grad():\n    outputs = model(**inputs)\ndetections = sv.Detections.from_transformers(outputs)  # raw model output\n\n# after\nwith torch.no_grad():\n    outputs = model(**inputs)\nresults = processor.post_process_object_detection(\n    outputs, threshold=0.5, target_sizes=torch.tensor([image.shape[:2]])\n)[0]\ndetections = sv.Detections.from_transformers(results, id2label=model.config.id2label)","handlingStrategy":"type-guard","validationCode":"SUPPORTED_TRANSFORMERS_KEYS = {'boxes', 'masks', 'segments_info', 'segmentation'}\nif not (SUPPORTED_TRANSFORMERS_KEYS & set(results.keys())):\n    raise ValueError(f'run a HF post-processor first; got keys {list(results.keys())}')\ndetections = sv.Detections.from_transformers(results, id2label=id2label)","typeGuard":"def is_post_processed_transformers_result(results: dict) -> bool:\n    return isinstance(results, dict) and bool(\n        {'boxes', 'masks', 'segments_info', 'segmentation'} & set(results)\n    )","tryCatchPattern":"try:\n    detections = sv.Detections.from_transformers(results, id2label)\nexcept ValueError as e:\n    if 'do not contain any valid fields' in str(e):\n        results = processor.post_process_object_detection(outputs, target_sizes=sizes)[0]\n        detections = sv.Detections.from_transformers(results, id2label)\n    else:\n        raise","preventionTips":["Always pass post-processor output, never model(**inputs)","Log results.keys() when integrating a new HF model","Pin transformers version; output key names drift across majors"],"tags":["transformers","huggingface","from-transformers","validation"],"backgroundTag":null,"analyzedSha":"7f254d9784d4c37e0f03cd89ddee164c8db099c0","analyzedAt":"2026-08-15T05:13:01.950Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}