{"record":{"id":"35ae5c8410928613","repo":"PaddlePaddle/PaddleOCR","slug":"you-have-to-specify-pixel-values","errorCode":null,"errorMessage":"You have to specify pixel_values","messagePattern":"You have to specify pixel_values","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"ppocr/modeling/backbones/rec_donut_swin.py","lineNumber":1256,"sourceCode":"                pixel_values = input_data[0]\n            else:\n                pixel_values = input_data\n        output_attentions = (\n            output_attentions\n            if output_attentions is not None\n            else self.config.output_attentions\n        )\n        output_hidden_states = (\n            output_hidden_states\n            if output_hidden_states is not None\n            else self.config.output_hidden_states\n        )\n        return_dict = (\n            return_dict if return_dict is not None else self.config.return_dict\n        )\n\n        if pixel_values is None:\n            raise ValueError(\"You have to specify pixel_values\")\n        num_channels = pixel_values.shape[1]\n        if num_channels == 1:\n            pixel_values = paddle.repeat_interleave(pixel_values, repeats=3, axis=1)\n\n        head_mask = self.get_head_mask(head_mask, len(self.config.depths))\n\n        embedding_output, input_dimensions = self.embeddings(\n            pixel_values, bool_masked_pos=bool_masked_pos\n        )\n\n        encoder_outputs = self.encoder(\n            embedding_output,\n            input_dimensions,\n            head_mask=head_mask,\n            output_attentions=output_attentions,\n            output_hidden_states=output_hidden_states,\n            return_dict=return_dict,\n        )","sourceCodeStart":1238,"sourceCodeEnd":1274,"githubUrl":"https://github.com/PaddlePaddle/PaddleOCR/blob/2661c7c0ef5c613e8f93c6e93b2e052399f0f854/ppocr/modeling/backbones/rec_donut_swin.py#L1238-L1274","documentation":"DonutSwinModel.forward requires the pixel input tensor: if pixel_values is None it raises ValueError('You have to specify pixel_values'). All other forward args (bool_masked_pos, head_mask, output_*) have defaults; the image tensor is the one mandatory argument.","triggerScenarios":"Calling model.forward() with no args, calling with keyword-arg names from another API (e.g. inputs=..., images=..., x=...) so pixel_values stays None, or a preprocessing step that returns None on failure and is passed through unchecked.","commonSituations":"Adapting a generic training loop that names the batch tensor differently; a dataset/dataloader yielding None for a corrupt image; wrapping the model in code that forwards **kwargs without the exact key 'pixel_values'.","solutions":["Pass the image tensor as the first positional arg or as pixel_values=: model(pixel_values=tensor)","Rename your batch key to pixel_values before calling forward","Guard the preprocessing: skip/raise on None samples in the dataset instead of forwarding them"],"exampleFix":"# before\nout = model(images=batch_img)   # pixel_values is None -> ValueError\n\n# after\nout = model(pixel_values=batch_img)","handlingStrategy":"validation","validationCode":"assert pixel_values is not None, 'pixel_values must be a tensor, not None'\nout = model(pixel_values=pixel_values)","typeGuard":"import paddle\n\ndef has_pixel_values(**kwargs) -> bool:\n    v = kwargs.get('pixel_values')\n    return isinstance(v, paddle.Tensor)","tryCatchPattern":null,"preventionTips":["Use the exact keyword pixel_values (or the first positional arg) when wrapping the model","Make the dataset raise on None images instead of forwarding them","Standardize your batch dict keys with the model's expected names once, in the collate function"],"tags":["api-usage","input-validation","donut-swin","required-argument"],"backgroundTag":null,"analyzedSha":"2661c7c0ef5c613e8f93c6e93b2e052399f0f854","analyzedAt":"2026-08-14T20:17:30.180Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}