roboflow/supervision · error · ValueError

The provided Transformers results do not contain any valid f

Error message

The provided Transformers results do not contain any valid fields. Expected fields are 'boxes', 'masks', 'segments_info' or 'segmentation'.

What it means

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.

Source

Thrown at src/supervision/detection/core.py:629

                **process_transformers_v5_segmentation_result(
                    transformers_results, id2label
                )
            )

        if "masks" in transformers_results or "png_string" in transformers_results:
            return cls(
                **process_transformers_v4_segmentation_result(
                    transformers_results, id2label
                )
            )

        if "boxes" in transformers_results:
            return cls(
                **process_transformers_detection_result(transformers_results, id2label)
            )

        else:
            raise ValueError(
                "The provided Transformers results do not contain any valid fields."
                " Expected fields are 'boxes', 'masks', 'segments_info' or"
                " 'segmentation'."
            )

    @classmethod
    def from_detectron2(cls, detectron2_results: Any) -> Detections:
        """
        Create a Detections object from the
        [Detectron2](https://github.com/facebookresearch/detectron2) inference result.

        Args:
            detectron2_results: The output of a
                Detectron2 model containing instances with prediction data.

        Returns:
            A Detections object containing the bounding boxes,
                class IDs, and confidences of the predictions.

View on GitHub (pinned to 7f254d9784)

Solutions

  1. 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]).
  2. Inspect the keys you are passing: print(results.keys()) and confirm 'boxes' (detection) or 'masks'/'segments_info' (segmentation) is present.
  3. If building the dict manually, include the 'boxes' key with the expected box tensor format.

Example fix

# before
with torch.no_grad():
    outputs = model(**inputs)
detections = sv.Detections.from_transformers(outputs)  # raw model output

# after
with torch.no_grad():
    outputs = model(**inputs)
results = processor.post_process_object_detection(
    outputs, threshold=0.5, target_sizes=torch.tensor([image.shape[:2]])
)[0]
detections = sv.Detections.from_transformers(results, id2label=model.config.id2label)
Defensive patterns

Strategy: type-guard

Validate before calling

SUPPORTED_TRANSFORMERS_KEYS = {'boxes', 'masks', 'segments_info', 'segmentation'}
if not (SUPPORTED_TRANSFORMERS_KEYS & set(results.keys())):
    raise ValueError(f'run a HF post-processor first; got keys {list(results.keys())}')
detections = sv.Detections.from_transformers(results, id2label=id2label)

Type guard

def is_post_processed_transformers_result(results: dict) -> bool:
    return isinstance(results, dict) and bool(
        {'boxes', 'masks', 'segments_info', 'segmentation'} & set(results)
    )

Try / catch

try:
    detections = sv.Detections.from_transformers(results, id2label)
except ValueError as e:
    if 'do not contain any valid fields' in str(e):
        results = processor.post_process_object_detection(outputs, target_sizes=sizes)[0]
        detections = sv.Detections.from_transformers(results, id2label)
    else:
        raise

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of roboflow/supervision@7f254d9784 (2026-08-15). Data as JSON: /api/errors/fa6bb5e80ff8cebe. Report an issue: GitHub.