{"record":{"id":"18a7c8fe00257488","repo":"opendatalab/MinerU","slug":"ppdoclayoutv2forobjectdetection-only-supports-infe","errorCode":null,"errorMessage":"PPDocLayoutV2ForObjectDetection only supports inference.","messagePattern":"PPDocLayoutV2ForObjectDetection only supports inference\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"mineru/model/layout/pp_doclayoutv2.py","lineNumber":828,"sourceCode":"            persistent=False,\n        )\n        self.post_init()\n\n    def forward(\n        self,\n        pixel_values: torch.FloatTensor,\n        pixel_mask: Optional[torch.LongTensor] = None,\n        encoder_outputs: Optional[torch.FloatTensor] = None,\n        inputs_embeds: Optional[torch.FloatTensor] = None,\n        decoder_inputs_embeds: Optional[torch.FloatTensor] = None,\n        labels: Optional[list[dict]] = None,\n        output_attentions: Optional[bool] = None,\n        output_hidden_states: Optional[bool] = None,\n        return_dict: Optional[bool] = None,\n        **kwargs,\n    ):\n        if labels is not None:\n            raise ValueError(\"PPDocLayoutV2ForObjectDetection only supports inference.\")\n\n        use_return_dict = return_dict if return_dict is not None else self.config.use_return_dict\n        outputs = self.model(\n            pixel_values,\n            pixel_mask=pixel_mask,\n            encoder_outputs=encoder_outputs,\n            inputs_embeds=inputs_embeds,\n            decoder_inputs_embeds=decoder_inputs_embeds,\n            labels=None,\n            output_attentions=output_attentions,\n            output_hidden_states=output_hidden_states,\n            return_dict=True,\n        )\n\n        raw_bboxes = outputs.intermediate_reference_points[:, -1]\n        logits = outputs.intermediate_logits[:, -1]\n\n        box_centers, box_sizes = raw_bboxes.split(2, dim=-1)","sourceCodeStart":810,"sourceCodeEnd":846,"githubUrl":"https://github.com/opendatalab/MinerU/blob/4fe4bde114a23ee5dd637eae99b767f4669bf58c/mineru/model/layout/pp_doclayoutv2.py#L810-L846","documentation":"ValueError raised in PPDocLayoutV2ForObjectDetection.forward when labels is not None. This DETR-style detection head is shipped for inference only — the training/loss branch is deliberately absent — so supplying labels (the HF training convention) is rejected with a clear message.","triggerScenarios":"model(pixel_values, labels=[{'class_labels': ..., 'boxes': ...}]) — i.e. calling forward the way you would with transformers' DetrForObjectDetection during training or eval-with-loss.","commonSituations":"Reusing HF detection training loops against this model; evaluation scripts that compute loss from labels; fine-tuning attempts on a checkpoint that only supports inference.","solutions":["Call forward without labels: model(pixel_values=..., pixel_mask=...).","For evaluation, compute metrics from the returned detections instead of model loss.","For fine-tuning, use the original upstream PP-DocLayout training codebase rather than this inference-only wrapper."],"exampleFix":"# before\noutputs = model(pixel_values=pv, pixel_mask=pm, labels=targets)  # ValueError\n\n# after\noutputs = model(pixel_values=pv, pixel_mask=pm)  # inference only","handlingStrategy":"validation","validationCode":"def inference_call(model, pixel_values, pixel_mask=None, **kwargs):\n    kwargs.pop('labels', None)  # training-style args are unsupported\n    return model(pixel_values=pixel_values, pixel_mask=pixel_mask, **kwargs)","typeGuard":null,"tryCatchPattern":"try:\n    outputs = model(pixel_values=pv, pixel_mask=pm, labels=targets)\nexcept ValueError as e:\n    if 'only supports inference' in str(e):\n        outputs = model(pixel_values=pv, pixel_mask=pm)  # retry without labels\n    else:\n        raise","preventionTips":["Do not pass labels to PP-DocLayoutV2ForObjectDetection — it is inference-only by design.","Compute evaluation metrics from predicted boxes vs targets yourself.","Adapt generic HF training loops with an inference-only branch for this model."],"tags":["pytorch","deep-learning","inference-only","object-detection","layout-model"],"backgroundTag":null,"analyzedSha":"4fe4bde114a23ee5dd637eae99b767f4669bf58c","analyzedAt":"2026-08-14T21:29:18.456Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}