opendatalab/MinerU · error · ValueError
PPDocLayoutV2ForObjectDetection only supports inference.
Error message
PPDocLayoutV2ForObjectDetection only supports inference.
What it means
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.
Source
Thrown at mineru/model/layout/pp_doclayoutv2.py:828
persistent=False,
)
self.post_init()
def forward(
self,
pixel_values: torch.FloatTensor,
pixel_mask: Optional[torch.LongTensor] = None,
encoder_outputs: Optional[torch.FloatTensor] = None,
inputs_embeds: Optional[torch.FloatTensor] = None,
decoder_inputs_embeds: Optional[torch.FloatTensor] = None,
labels: Optional[list[dict]] = None,
output_attentions: Optional[bool] = None,
output_hidden_states: Optional[bool] = None,
return_dict: Optional[bool] = None,
**kwargs,
):
if labels is not None:
raise ValueError("PPDocLayoutV2ForObjectDetection only supports inference.")
use_return_dict = return_dict if return_dict is not None else self.config.use_return_dict
outputs = self.model(
pixel_values,
pixel_mask=pixel_mask,
encoder_outputs=encoder_outputs,
inputs_embeds=inputs_embeds,
decoder_inputs_embeds=decoder_inputs_embeds,
labels=None,
output_attentions=output_attentions,
output_hidden_states=output_hidden_states,
return_dict=True,
)
raw_bboxes = outputs.intermediate_reference_points[:, -1]
logits = outputs.intermediate_logits[:, -1]
box_centers, box_sizes = raw_bboxes.split(2, dim=-1)View on GitHub (pinned to 4fe4bde114)
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.
Example fix
# before outputs = model(pixel_values=pv, pixel_mask=pm, labels=targets) # ValueError # after outputs = model(pixel_values=pv, pixel_mask=pm) # inference only
Defensive patterns
Strategy: validation
Validate before calling
def inference_call(model, pixel_values, pixel_mask=None, **kwargs):
kwargs.pop('labels', None) # training-style args are unsupported
return model(pixel_values=pixel_values, pixel_mask=pixel_mask, **kwargs) Try / catch
try:
outputs = model(pixel_values=pv, pixel_mask=pm, labels=targets)
except ValueError as e:
if 'only supports inference' in str(e):
outputs = model(pixel_values=pv, pixel_mask=pm) # retry without labels
else:
raise Prevention
- 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.
When it happens
Trigger: model(pixel_values, labels=[{'class_labels': ..., 'boxes': ...}]) — i.e. calling forward the way you would with transformers' DetrForObjectDetection during training or eval-with-loss.
Common situations: 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.
Related errors
- PP-DocLayoutV2 reading-order mask must be 2D or 4D, got shap
- The hidden size ({config.hidden_size}) is not a multiple of
- PP-DocLayoutV2 reading-order inference requires a mask tenso
- Attention mask batch size {attention_mask.shape[0]} does not
- Unsupported image type for PP-DocLayoutV2: {type(image)}
AI-assisted analysis of opendatalab/MinerU@4fe4bde114 (2026-08-14).
Data as JSON: /api/errors/18a7c8fe00257488.
Report an issue: GitHub.