Buckets:

download
raw
99.9 kB
import"../chunks/DsnmJJEf.js";import{i as Je,h as Ue,C as ke,H as l,b as je,a as c,D as r,E as ze,s as xe}from"../chunks/CN3cOuQA.js";import{p as Ze,o as We,s as e,f as g,a as i,b as Re,c as n,d,r as t,n as u}from"../chunks/DdiSzEty.js";import{T as p}from"../chunks/Biyddybe.js";import{E as te}from"../chunks/BpTh2jDR.js";import{H as re}from"../chunks/CvgQlE2K.js";const De='{"title":"Donut","local":"donut","sections":[{"title":"Notes","local":"notes","sections":[],"depth":2},{"title":"DonutSwinConfig","local":"transformers.DonutSwinConfig","sections":[],"depth":2},{"title":"DonutImageProcessor","local":"transformers.DonutImageProcessor","sections":[],"depth":2},{"title":"DonutImageProcessorPil","local":"transformers.DonutImageProcessorPil","sections":[],"depth":2},{"title":"DonutProcessor","local":"transformers.DonutProcessor","sections":[],"depth":2},{"title":"DonutSwinModel","local":"transformers.DonutSwinModel","sections":[],"depth":2},{"title":"DonutSwinForImageClassification","local":"transformers.DonutSwinForImageClassification","sections":[],"depth":2}],"depth":1}';var Ce=d('<meta name="hf:doc:metadata"/>'),Ne=d("<!> <!>",1),ae=d("<p>Example:</p> <!>",1),Pe=d(`<p>This class method is simply calling the feature extractor <a href="/docs/transformers/pr_51549/en/main_classes/feature_extractor#transformers.FeatureExtractionMixin.from_pretrained">from_pretrained()</a>, image processor <a href="/docs/transformers/pr_51549/en/internal/image_processing_utils#transformers.ImageProcessingMixin">ImageProcessingMixin</a> and the tokenizer <code>~tokenization_utils_base.PreTrainedTokenizer.from_pretrained</code> methods. Please refer to the docstrings of the
methods above for more information.</p>`),Be=d(`<p>This class method is simply calling <a href="/docs/transformers/pr_51549/en/main_classes/feature_extractor#transformers.FeatureExtractionMixin.save_pretrained">save_pretrained()</a> and <a href="/docs/transformers/pr_51549/en/internal/tokenization_utils#transformers.PreTrainedTokenizerBase.save_pretrained">save_pretrained()</a>. Please refer to the docstrings of the
methods above for more information.</p>`),ie=d(`<p>Although the recipe for forward pass needs to be defined within this function, one should call the <code>Module</code> instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.</p>`),Ve=d(`<p>Note that it’s possible to fine-tune DonutSwin on higher resolution images than the ones it has been trained on, by
setting <code>interpolate_pos_encoding</code> to <code>True</code> in the forward of the model. This will interpolate the pre-trained
position embeddings to the higher resolution.</p>`),Ge=d(`<p></p> <p><em>This model was published in HF papers on 2021-11-30 and contributed to Hugging Face Transformers on 2022-08-12.</em></p> <!> <!> <p><a href="https://huggingface.co/papers/2111.15664" rel="nofollow">Donut (Document Understanding Transformer)</a> is a visual document understanding model that doesn’t require an Optical Character Recognition (OCR) engine. Unlike traditional approaches that extract text using OCR before processing, Donut employs an end-to-end Transformer-based architecture to directly analyze document images. This eliminates OCR-related inefficiencies making it more accurate and adaptable to diverse languages and formats.</p> <p>Donut features vision encoder (<a href="./swin">Swin</a>) and a text decoder (<a href="./bart">BART</a>). Swin converts document images into embeddings and BART processes them into meaningful text sequences.</p> <p>You can find all the original Donut checkpoints under the <a href="https://huggingface.co/naver-clova-ix" rel="nofollow">Naver Clova Information Extraction</a> organization.</p> <blockquote class="tip"><p>Click on the Donut models in the right sidebar for more examples of how to apply Donut to different language and vision tasks.</p></blockquote> <p>The examples below demonstrate how to perform document understanding tasks using Donut with <a href="/docs/transformers/pr_51549/en/main_classes/pipelines#transformers.Pipeline">Pipeline</a> and <a href="/docs/transformers/pr_51549/en/model_doc/auto#transformers.AutoModel">AutoModel</a></p> <!> <p>Quantization reduces the memory burden of large models by representing the weights in a lower precision. Refer to the <a href="../quantization/overview">Quantization</a> overview for more available quantization backends.</p> <p>The example below uses <a href="../quantization/torchao">torchao</a> to only quantize the weights to int4.</p> <!> <!> <ul><li><p>Use Donut for document image classification as shown below.</p> <!></li> <li><p>Use Donut for document parsing as shown below.</p> <!></li></ul> <!> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>This is the configuration class to store the configuration of a Donut SwinModel. It is used to instantiate a Donut Swin
model according to the specified arguments, defining the model architecture. Instantiating a configuration with the
defaults will yield a similar configuration to that of the <a href="https://huggingface.co/naver-clova-ix/donut-base" rel="nofollow">naver-clova-ix/donut-base</a></p> <p>Configuration objects inherit from <a href="/docs/transformers/pr_51549/en/main_classes/configuration#transformers.PreTrainedConfig">PreTrainedConfig</a> and can be used to control the model outputs. Read the
documentation from <a href="/docs/transformers/pr_51549/en/main_classes/configuration#transformers.PreTrainedConfig">PreTrainedConfig</a> for more information.</p> <!></div> <!> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Constructs a image_processor_class image processor.</p> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!></div></div> <!> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Constructs a image_processor_class image processor.</p> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!></div></div> <!> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Constructs a DonutProcessor which wraps a image processor and a tokenizer into a single processor.</p> <p><a href="/docs/transformers/pr_51549/en/model_doc/donut#transformers.DonutProcessor">DonutProcessor</a> offers all the functionalities of <code>image_processor_class</code> and <code>tokenizer_class</code>. See the <code>~image_processor_class</code> and <code>~tokenizer_class</code> for more information.</p> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!></div> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Instantiate a processor associated with a pretrained model.</p> <!></div> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Saves the attributes of this processor (feature extractor, tokenizer…) in the specified directory so that it
can be reloaded using the <a href="/docs/transformers/pr_51549/en/model_doc/trocr#transformers.TrOCRProcessor.from_pretrained">from_pretrained()</a> method.</p> <!></div> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>This method forwards all its arguments to PreTrainedTokenizer’s <a href="/docs/transformers/pr_51549/en/internal/tokenization_utils#transformers.PreTrainedTokenizerBase.batch_decode">batch_decode()</a>. Please
refer to the docstring of this method for more information.</p></div> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>This method forwards all its arguments to PreTrainedTokenizer’s <a href="/docs/transformers/pr_51549/en/internal/tokenization_utils#transformers.PreTrainedTokenizerBase.decode">decode()</a>. Please refer to
the docstring of this method for more information.</p></div></div> <!> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>The bare Donut Swin Model outputting raw hidden-states without any specific head on top.</p> <p>This model inherits from <a href="/docs/transformers/pr_51549/en/main_classes/model#transformers.PreTrainedModel">PreTrainedModel</a>. Check the superclass documentation for the generic methods the
library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
etc.)</p> <p>This model is also a PyTorch <a href="https://pytorch.org/docs/stable/nn.html#torch.nn.Module" rel="nofollow">torch.nn.Module</a> subclass.
Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
and behavior.</p> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>The <a href="/docs/transformers/pr_51549/en/model_doc/donut#transformers.DonutSwinModel">DonutSwinModel</a> forward method, overrides the <code>__call__</code> special method.</p> <!> <ul><li><p><strong>last_hidden_state</strong> (<code>torch.Tensor</code> of shape <code>(batch_size, sequence_length, hidden_size)</code>, <em>optional</em>) — Sequence of hidden-states at the output of the last layer of the model.</p></li> <li><p><strong>pooler_output</strong> (<code>torch.Tensor</code> of shape <code>(batch_size, hidden_size)</code>, <em>optional</em>, returned when <code>add_pooling_layer=True</code> is passed) — Average pooling of the last layer hidden-state.</p></li> <li><p><strong>hidden_states</strong> (<code>tuple[torch.Tensor, ...]</code>, <em>optional</em>, returned when <code>output_hidden_states=True</code> is passed or when <code>config.output_hidden_states=True</code>) — Tuple of <code>torch.Tensor</code> (one for the output of the embeddings, if the model has an embedding layer, +
one for the output of each layer) of shape <code>(batch_size, sequence_length, hidden_size)</code>.</p> <p>Hidden-states of the model at the output of each layer plus the optional initial embedding outputs.</p></li> <li><p><strong>attentions</strong> (<code>tuple[torch.Tensor, ...]</code>, <em>optional</em>, returned when <code>output_attentions=True</code> is passed or when <code>config.output_attentions=True</code>) — Tuple of <code>torch.Tensor</code> (one for each layer) of shape <code>(batch_size, num_heads, sequence_length, sequence_length)</code>.</p> <p>Attentions weights after the attention softmax, used to compute the weighted average in the self-attention
heads.</p></li> <li><p><strong>reshaped_hidden_states</strong> (<code>tuple(torch.Tensor)</code>, <em>optional</em>, returned when <code>output_hidden_states=True</code> is passed or when <code>config.output_hidden_states=True</code>) — Tuple of <code>torch.Tensor</code> (one for the output of the embeddings + one for the output of each stage) of
shape <code>(batch_size, hidden_size, height, width)</code>.</p> <p>Hidden-states of the model at the output of each layer plus the initial embedding outputs reshaped to
include the spatial dimensions.</p></li></ul></div></div> <!> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>DonutSwin Model transformer with an image classification head on top (a linear layer on top of the final hidden state of
the [CLS] token) e.g. for ImageNet.</p> <!> <p>This model inherits from <a href="/docs/transformers/pr_51549/en/main_classes/model#transformers.PreTrainedModel">PreTrainedModel</a>. Check the superclass documentation for the generic methods the
library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
etc.)</p> <p>This model is also a PyTorch <a href="https://pytorch.org/docs/stable/nn.html#torch.nn.Module" rel="nofollow">torch.nn.Module</a> subclass.
Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
and behavior.</p> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>The <a href="/docs/transformers/pr_51549/en/model_doc/donut#transformers.DonutSwinForImageClassification">DonutSwinForImageClassification</a> forward method, overrides the <code>__call__</code> special method.</p> <!> <ul><li><p><strong>loss</strong> (<code>torch.Tensor</code> of shape <code>(1,)</code>, <em>optional</em>, returned when <code>labels</code> is provided) — Classification (or regression if config.num_labels==1) loss.</p></li> <li><p><strong>logits</strong> (<code>torch.Tensor</code> of shape <code>(batch_size, config.num_labels)</code>) — Classification (or regression if config.num_labels==1) scores (before SoftMax).</p></li> <li><p><strong>hidden_states</strong> (<code>tuple[torch.Tensor, ...]</code>, <em>optional</em>, returned when <code>output_hidden_states=True</code> is passed or when <code>config.output_hidden_states=True</code>) — Tuple of <code>torch.Tensor</code> (one for the output of the embeddings, if the model has an embedding layer, +
one for the output of each layer) of shape <code>(batch_size, sequence_length, hidden_size)</code>.</p> <p>Hidden-states of the model at the output of each layer plus the optional initial embedding outputs.</p></li> <li><p><strong>attentions</strong> (<code>tuple[torch.Tensor, ...]</code>, <em>optional</em>, returned when <code>output_attentions=True</code> is passed or when <code>config.output_attentions=True</code>) — Tuple of <code>torch.Tensor</code> (one for each layer) of shape <code>(batch_size, num_heads, sequence_length, sequence_length)</code>.</p> <p>Attentions weights after the attention softmax, used to compute the weighted average in the self-attention
heads.</p></li> <li><p><strong>reshaped_hidden_states</strong> (<code>tuple(torch.Tensor)</code>, <em>optional</em>, returned when <code>output_hidden_states=True</code> is passed or when <code>config.output_hidden_states=True</code>) — Tuple of <code>torch.Tensor</code> (one for the output of the embeddings + one for the output of each stage) of
shape <code>(batch_size, hidden_size, height, width)</code>.</p> <p>Hidden-states of the model at the output of each layer plus the initial embedding outputs reshaped to
include the spatial dimensions.</p></li></ul> <!></div></div> <!> <p></p>`,1);function Ee(le,de){Ze(de,!1),We(()=>{new URLSearchParams(window.location.search).get("fw")}),Je();var j=Ge();Ue("12fp0p4",o=>{var a=Ce();xe(a,"content",De),i(o,a)});var z=e(g(j),4);ke(z,{containerStyle:"float: inline-end; margin-inline-start: 10px; display: inline-flex; position: relative; z-index: 10;"});var x=e(z,2);l(x,{title:"Donut",local:"donut",headingTag:"h1"});var Z=e(x,12);je(Z,{id:"usage",options:["Pipeline","AutoModel"],children:(o,a)=>{var s=Ne(),m=g(s);re(m,{id:"usage",option:"Pipeline",children:(k,Ie)=>{c(k,{code:"JTIzJTIwcGlwJTIwaW5zdGFsbCUyMGRhdGFzZXRzJTBBZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMHBpcGVsaW5lJTBBJTBBJTBBcGlwZWxpbmUlMjAlM0QlMjBwaXBlbGluZSglMEElMjAlMjAlMjAlMjB0YXNrJTNEJTIyZG9jdW1lbnQtcXVlc3Rpb24tYW5zd2VyaW5nJTIyJTJDJTBBJTIwJTIwJTIwJTIwbW9kZWwlM0QlMjJuYXZlci1jbG92YS1peCUyRmRvbnV0LWJhc2UtZmluZXR1bmVkLWRvY3ZxYSUyMiUyQyUwQSUyMCUyMCUyMCUyMGRldmljZSUzRDAlMkMlMEEpJTBBZGF0YXNldCUyMCUzRCUyMGxvYWRfZGF0YXNldCglMjJoZi1pbnRlcm5hbC10ZXN0aW5nJTJGZXhhbXBsZS1kb2N1bWVudHMlMjIlMkMlMjBzcGxpdCUzRCUyMnRlc3QlMjIpJTBBaW1hZ2UlMjAlM0QlMjBkYXRhc2V0JTVCMCU1RCU1QiUyMmltYWdlJTIyJTVEJTBBJTBBcGlwZWxpbmUoaW1hZ2UlM0RpbWFnZSUyQyUyMHF1ZXN0aW9uJTNEJTIyV2hhdCUyMHRpbWUlMjBpcyUyMHRoZSUyMGNvZmZlZSUyMGJyZWFrJTNGJTIyKQ==",highlighted:`<span class="hljs-comment"># pip install datasets</span>
<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> pipeline
pipeline = pipeline(
task=<span class="hljs-string">&quot;document-question-answering&quot;</span>,
model=<span class="hljs-string">&quot;naver-clova-ix/donut-base-finetuned-docvqa&quot;</span>,
device=<span class="hljs-number">0</span>,
)
dataset = load_dataset(<span class="hljs-string">&quot;hf-internal-testing/example-documents&quot;</span>, split=<span class="hljs-string">&quot;test&quot;</span>)
image = dataset[<span class="hljs-number">0</span>][<span class="hljs-string">&quot;image&quot;</span>]
pipeline(image=image, question=<span class="hljs-string">&quot;What time is the coffee break?&quot;</span>)`,lang:"python",wrap:!1})},$$slots:{default:!0}});var ve=e(m,2);re(ve,{id:"usage",option:"AutoModel",children:(k,Ie)=>{c(k,{code:"JTIzJTIwcGlwJTIwaW5zdGFsbCUyMGRhdGFzZXRzJTBBZnJvbSUyMGRhdGFzZXRzJTIwaW1wb3J0JTIwbG9hZF9kYXRhc2V0JTBBJTBBZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Nb2RlbEZvckltYWdlVGV4dFRvVGV4dCUyQyUyMEF1dG9Qcm9jZXNzb3IlMEElMEElMEFwcm9jZXNzb3IlMjAlM0QlMjBBdXRvUHJvY2Vzc29yLmZyb21fcHJldHJhaW5lZCglMjJuYXZlci1jbG92YS1peCUyRmRvbnV0LWJhc2UtZmluZXR1bmVkLWRvY3ZxYSUyMiklMEFtb2RlbCUyMCUzRCUyMEF1dG9Nb2RlbEZvckltYWdlVGV4dFRvVGV4dC5mcm9tX3ByZXRyYWluZWQoJTIybmF2ZXItY2xvdmEtaXglMkZkb251dC1iYXNlLWZpbmV0dW5lZC1kb2N2cWElMjIlMkMlMjBkZXZpY2VfbWFwJTNEJTIyYXV0byUyMiklMEElMEFkYXRhc2V0JTIwJTNEJTIwbG9hZF9kYXRhc2V0KCUyMmhmLWludGVybmFsLXRlc3RpbmclMkZleGFtcGxlLWRvY3VtZW50cyUyMiUyQyUyMHNwbGl0JTNEJTIydGVzdCUyMiklMEFpbWFnZSUyMCUzRCUyMGRhdGFzZXQlNUIwJTVEJTVCJTIyaW1hZ2UlMjIlNUQlMEFxdWVzdGlvbiUyMCUzRCUyMCUyMldoYXQlMjB0aW1lJTIwaXMlMjB0aGUlMjBjb2ZmZWUlMjBicmVhayUzRiUyMiUwQXRhc2tfcHJvbXB0JTIwJTNEJTIwZiUyMiUzQ3NfZG9jdnFhJTNFJTNDc19xdWVzdGlvbiUzRSU3QnF1ZXN0aW9uJTdEJTNDJTJGc19xdWVzdGlvbiUzRSUzQ3NfYW5zd2VyJTNFJTIyJTBBaW5wdXRzJTIwJTNEJTIwcHJvY2Vzc29yKGltYWdlJTJDJTIwdGFza19wcm9tcHQlMkMlMjByZXR1cm5fdGVuc29ycyUzRCUyMnB0JTIyKS50byhtb2RlbC5kZXZpY2UpJTBBJTBBb3V0cHV0cyUyMCUzRCUyMG1vZGVsLmdlbmVyYXRlKCUwQSUyMCUyMCUyMCUyMGlucHV0X2lkcyUzRGlucHV0cy5pbnB1dF9pZHMlMkMlMEElMjAlMjAlMjAlMjBwaXhlbF92YWx1ZXMlM0RpbnB1dHMucGl4ZWxfdmFsdWVzJTJDJTBBJTIwJTIwJTIwJTIwbWF4X2xlbmd0aCUzRDUxMiUwQSklMEFhbnN3ZXIlMjAlM0QlMjBwcm9jZXNzb3IuZGVjb2RlKG91dHB1dHMlNUIwJTVEJTJDJTIwc2tpcF9zcGVjaWFsX3Rva2VucyUzRFRydWUpJTBBcHJpbnQoYW5zd2VyKQ==",highlighted:`<span class="hljs-comment"># pip install datasets</span>
<span class="hljs-keyword">from</span> datasets <span class="hljs-keyword">import</span> load_dataset
<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForImageTextToText, AutoProcessor
processor = AutoProcessor.from_pretrained(<span class="hljs-string">&quot;naver-clova-ix/donut-base-finetuned-docvqa&quot;</span>)
model = AutoModelForImageTextToText.from_pretrained(<span class="hljs-string">&quot;naver-clova-ix/donut-base-finetuned-docvqa&quot;</span>, device_map=<span class="hljs-string">&quot;auto&quot;</span>)
dataset = load_dataset(<span class="hljs-string">&quot;hf-internal-testing/example-documents&quot;</span>, split=<span class="hljs-string">&quot;test&quot;</span>)
image = dataset[<span class="hljs-number">0</span>][<span class="hljs-string">&quot;image&quot;</span>]
question = <span class="hljs-string">&quot;What time is the coffee break?&quot;</span>
task_prompt = <span class="hljs-string">f&quot;&lt;s_docvqa&gt;&lt;s_question&gt;<span class="hljs-subst">{question}</span>&lt;/s_question&gt;&lt;s_answer&gt;&quot;</span>
inputs = processor(image, task_prompt, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>).to(model.device)
outputs = model.generate(
input_ids=inputs.input_ids,
pixel_values=inputs.pixel_values,
max_length=<span class="hljs-number">512</span>
)
answer = processor.decode(outputs[<span class="hljs-number">0</span>], skip_special_tokens=<span class="hljs-literal">True</span>)
<span class="hljs-built_in">print</span>(answer)`,lang:"python",wrap:!1})},$$slots:{default:!0}}),i(o,s)},$$slots:{default:!0}});var W=e(Z,6);c(W,{code:"JTIzJTIwcGlwJTIwaW5zdGFsbCUyMGRhdGFzZXRzJTIwdG9yY2hhbyUwQWZyb20lMjBkYXRhc2V0cyUyMGltcG9ydCUyMGxvYWRfZGF0YXNldCUwQSUwQWZyb20lMjB0cmFuc2Zvcm1lcnMlMjBpbXBvcnQlMjBBdXRvTW9kZWxGb3JJbWFnZVRleHRUb1RleHQlMkMlMjBBdXRvUHJvY2Vzc29yJTJDJTIwVG9yY2hBb0NvbmZpZyUwQSUwQSUwQXF1YW50aXphdGlvbl9jb25maWclMjAlM0QlMjBUb3JjaEFvQ29uZmlnKCUyMmludDRfd2VpZ2h0X29ubHklMjIlMkMlMjBncm91cF9zaXplJTNEMTI4KSUwQXByb2Nlc3NvciUyMCUzRCUyMEF1dG9Qcm9jZXNzb3IuZnJvbV9wcmV0cmFpbmVkKCUyMm5hdmVyLWNsb3ZhLWl4JTJGZG9udXQtYmFzZS1maW5ldHVuZWQtZG9jdnFhJTIy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BYW5zd2VyJTIwJTNEJTIwcHJvY2Vzc29yLmRlY29kZShvdXRwdXRzJTVCMCU1RCUyQyUyMHNraXBfc3BlY2lhbF90b2tlbnMlM0RUcnVlKSUwQXByaW50KGFuc3dlcik=",highlighted:`<span class="hljs-comment"># pip install datasets torchao</span>
<span class="hljs-keyword">from</span> datasets <span class="hljs-keyword">import</span> load_dataset
<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForImageTextToText, AutoProcessor, TorchAoConfig
quantization_config = TorchAoConfig(<span class="hljs-string">&quot;int4_weight_only&quot;</span>, group_size=<span class="hljs-number">128</span>)
processor = AutoProcessor.from_pretrained(<span class="hljs-string">&quot;naver-clova-ix/donut-base-finetuned-docvqa&quot;</span>)
model = AutoModelForImageTextToText.from_pretrained(<span class="hljs-string">&quot;naver-clova-ix/donut-base-finetuned-docvqa&quot;</span>, quantization_config=quantization_config, device_map=<span class="hljs-string">&quot;auto&quot;</span>)
dataset = load_dataset(<span class="hljs-string">&quot;hf-internal-testing/example-documents&quot;</span>, split=<span class="hljs-string">&quot;test&quot;</span>)
image = dataset[<span class="hljs-number">0</span>][<span class="hljs-string">&quot;image&quot;</span>]
question = <span class="hljs-string">&quot;What time is the coffee break?&quot;</span>
task_prompt = <span class="hljs-string">f&quot;&lt;s_docvqa&gt;&lt;s_question&gt;<span class="hljs-subst">{question}</span>&lt;/s_question&gt;&lt;s_answer&gt;&quot;</span>
inputs = processor(image, task_prompt, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>).to(model.device)
outputs = model.generate(
input_ids=inputs.input_ids,
pixel_values=inputs.pixel_values,
max_length=<span class="hljs-number">512</span>
)
answer = processor.decode(outputs[<span class="hljs-number">0</span>], skip_special_tokens=<span class="hljs-literal">True</span>)
<span class="hljs-built_in">print</span>(answer)`,lang:"python",wrap:!1});var R=e(W,2);l(R,{title:"Notes",local:"notes",headingTag:"h2"});var h=e(R,2),f=n(h),ce=e(n(f),2);c(ce,{code:"aW1wb3J0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lMEFzZXF1ZW5jZSUyMCUzRCUyMHNlcXVlbmNlLnJlcGxhY2UocHJvY2Vzc29yLnRva2VuaXplci5lb3NfdG9rZW4lMkMlMjAlMjIlMjIpLnJlcGxhY2UocHJvY2Vzc29yLnRva2VuaXplci5wYWRfdG9rZW4lMkMlMjAlMjIlMjIpJTBBc2VxdWVuY2UlMjAlM0QlMjByZS5zdWIociUyMiUzQy4qJTNGJTNFJTIyJTJDJTIwJTIyJTIyJTJDJTIwc2VxdWVuY2UlMkMlMjBjb3VudCUzRDEpLnN0cmlwKCklMjAlMjAlMjMlMjByZW1vdmUlMjBmaXJzdCUyMHRhc2slMjBzdGFydCUyMHRva2VuJTBBcHJpbnQocHJvY2Vzc29yLnRva2VuMmpzb24oc2VxdWVuY2UpKSUwQSU3QidjbGFzcyclM0ElMjAnYWR2ZXJ0aXNlbWVudCclN0Q=",highlighted:`<span class="hljs-keyword">import</span> re
<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> DonutProcessor, VisionEncoderDecoderModel
<span class="hljs-keyword">from</span> datasets <span class="hljs-keyword">import</span> load_dataset
<span class="hljs-keyword">import</span> torch
processor = DonutProcessor.from_pretrained(<span class="hljs-string">&quot;naver-clova-ix/donut-base-finetuned-rvlcdip&quot;</span>)
model = VisionEncoderDecoderModel.from_pretrained(<span class="hljs-string">&quot;naver-clova-ix/donut-base-finetuned-rvlcdip&quot;</span>, device_map=<span class="hljs-string">&quot;auto&quot;</span>)
model.to(model.device) <span class="hljs-comment"># doctest: +IGNORE_RESULT</span>
<span class="hljs-comment"># load document image</span>
dataset = load_dataset(<span class="hljs-string">&quot;hf-internal-testing/example-documents&quot;</span>, split=<span class="hljs-string">&quot;test&quot;</span>)
image = dataset[<span class="hljs-number">1</span>][<span class="hljs-string">&quot;image&quot;</span>]
<span class="hljs-comment"># prepare decoder inputs</span>
task_prompt = <span class="hljs-string">&quot;&lt;s_rvlcdip&gt;&quot;</span>
decoder_input_ids = processor.tokenizer(task_prompt, add_special_tokens=<span class="hljs-literal">False</span>, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>).to(model.device).input_ids
pixel_values = processor(image, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>).to(model.device).pixel_values
outputs = model.generate(
pixel_values.to(model.device),
decoder_input_ids=decoder_input_ids.to(model.device),
max_length=model.decoder.config.max_position_embeddings,
pad_token_id=processor.tokenizer.pad_token_id,
eos_token_id=processor.tokenizer.eos_token_id,
use_cache=<span class="hljs-literal">True</span>,
bad_words_ids=[[processor.tokenizer.unk_token_id]],
return_dict_in_generate=<span class="hljs-literal">True</span>,
)
sequence = processor.batch_decode(outputs.sequences)[<span class="hljs-number">0</span>]
sequence = sequence.replace(processor.tokenizer.eos_token, <span class="hljs-string">&quot;&quot;</span>).replace(processor.tokenizer.pad_token, <span class="hljs-string">&quot;&quot;</span>)
sequence = re.sub(<span class="hljs-string">r&quot;&lt;.*?&gt;&quot;</span>, <span class="hljs-string">&quot;&quot;</span>, sequence, count=<span class="hljs-number">1</span>).strip() <span class="hljs-comment"># remove first task start token</span>
<span class="hljs-built_in">print</span>(processor.token2json(sequence))
{<span class="hljs-string">&#x27;class&#x27;</span>: <span class="hljs-string">&#x27;advertisement&#x27;</span>}`,lang:"py",wrap:!1}),t(f);var D=e(f,2),me=e(n(D),2);c(me,{code:"aW1wb3J0JTIwcmUlMEElMjAlMjAlMjAlMjBmcm9tJTIwZGF0YXNldHMlMjBpbXBvcnQlMjBsb2FkX2RhdGFzZXQlMEFmcm9tJTIwdHJhbnNmb3JtZXJzJTIwaW1wb3J0JTIwRG9udXRQcm9jZXNzb3IlMkMlMjBWaXNpb25FbmNvZGVyRGVjb2Rlck1vZGVsJTBBaW1wb3J0JTIwdG9yY2glMEElMEFwcm9jZXNzb3IlMjAlM0QlMjBEb251dFByb2Nlc3Nvci5mcm9tX3ByZXRyYWluZWQoJTIybmF2ZXItY2xvdmEtaXglMkZkb251dC1iYXNlLWZpbmV0dW5lZC1jb3JkLXYyJTIyK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ydCUyMHRva2VuJTBBcHJpbnQocHJvY2Vzc29yLnRva2VuMmpzb24oc2VxdWVuY2UpKSUwQSU3QidtZW51JyUzQSUyMCU3QidubSclM0ElMjAnQ0lOTkFNT04lMjBTVUdBUiclMkMlMjAndW5pdHByaWNlJyUzQSUyMCcxNyUyQzAwMCclMkMlMjAnY250JyUzQSUyMCcxJTIweCclMkMlMjAncHJpY2UnJTNBJTIwJzE3JTJDMDAwJyU3RCUyQyUyMCdzdWJfdG90YWwnJTNBJTIwJTdCJ3N1YnRvdGFsX3ByaWNlJyUzQSUyMCcxNyUyQzAwMCclN0QlMkMlMjAndG90YWwnJTNBJTIwJTBBJTdCJ3RvdGFsX3ByaWNlJyUzQSUyMCcxNyUyQzAwMCclMkMlMjAnY2FzaHByaWNlJyUzQSUyMCcyMCUyQzAwMCclMkMlMjAnY2hhbmdlcHJpY2UnJTNBJTIwJzMlMkMwMDAnJTdEJTdE",highlighted:`<span class="hljs-keyword">import</span> re
<span class="hljs-keyword">from</span> datasets <span class="hljs-keyword">import</span> load_dataset
<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> DonutProcessor, VisionEncoderDecoderModel
<span class="hljs-keyword">import</span> torch
processor = DonutProcessor.from_pretrained(<span class="hljs-string">&quot;naver-clova-ix/donut-base-finetuned-cord-v2&quot;</span>)
model = VisionEncoderDecoderModel.from_pretrained(<span class="hljs-string">&quot;naver-clova-ix/donut-base-finetuned-cord-v2&quot;</span>, device_map=<span class="hljs-string">&quot;auto&quot;</span>)
model.to(model.device) <span class="hljs-comment"># doctest: +IGNORE_RESULT</span>
<span class="hljs-comment"># load document image</span>
dataset = load_dataset(<span class="hljs-string">&quot;hf-internal-testing/example-documents&quot;</span>, split=<span class="hljs-string">&quot;test&quot;</span>)
image = dataset[<span class="hljs-number">2</span>][<span class="hljs-string">&quot;image&quot;</span>]
<span class="hljs-comment"># prepare decoder inputs</span>
task_prompt = <span class="hljs-string">&quot;&lt;s_cord-v2&gt;&quot;</span>
decoder_input_ids = processor.tokenizer(task_prompt, add_special_tokens=<span class="hljs-literal">False</span>, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>).to(model.device).input_ids
pixel_values = processor(image, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>).to(model.device).pixel_values
outputs = model.generate(
pixel_values.to(model.device),
decoder_input_ids=decoder_input_ids.to(model.device),
max_length=model.decoder.config.max_position_embeddings,
pad_token_id=processor.tokenizer.pad_token_id,
eos_token_id=processor.tokenizer.eos_token_id,
use_cache=<span class="hljs-literal">True</span>,
bad_words_ids=[[processor.tokenizer.unk_token_id]],
return_dict_in_generate=<span class="hljs-literal">True</span>,
)
sequence = processor.batch_decode(outputs.sequences)[<span class="hljs-number">0</span>]
sequence = sequence.replace(processor.tokenizer.eos_token, <span class="hljs-string">&quot;&quot;</span>).replace(processor.tokenizer.pad_token, <span class="hljs-string">&quot;&quot;</span>)
sequence = re.sub(<span class="hljs-string">r&quot;&lt;.*?&gt;&quot;</span>, <span class="hljs-string">&quot;&quot;</span>, sequence, count=<span class="hljs-number">1</span>).strip() <span class="hljs-comment"># remove first task start token</span>
<span class="hljs-built_in">print</span>(processor.token2json(sequence))
{<span class="hljs-string">&#x27;menu&#x27;</span>: {<span class="hljs-string">&#x27;nm&#x27;</span>: <span class="hljs-string">&#x27;CINNAMON SUGAR&#x27;</span>, <span class="hljs-string">&#x27;unitprice&#x27;</span>: <span class="hljs-string">&#x27;17,000&#x27;</span>, <span class="hljs-string">&#x27;cnt&#x27;</span>: <span class="hljs-string">&#x27;1 x&#x27;</span>, <span class="hljs-string">&#x27;price&#x27;</span>: <span class="hljs-string">&#x27;17,000&#x27;</span>}, <span class="hljs-string">&#x27;sub_total&#x27;</span>: {<span class="hljs-string">&#x27;subtotal_price&#x27;</span>: <span class="hljs-string">&#x27;17,000&#x27;</span>}, <span class="hljs-string">&#x27;total&#x27;</span>:
{<span class="hljs-string">&#x27;total_price&#x27;</span>: <span class="hljs-string">&#x27;17,000&#x27;</span>, <span class="hljs-string">&#x27;cashprice&#x27;</span>: <span class="hljs-string">&#x27;20,000&#x27;</span>, <span class="hljs-string">&#x27;changeprice&#x27;</span>: <span class="hljs-string">&#x27;3,000&#x27;</span>}}`,lang:"py",wrap:!1}),t(D),t(h);var C=e(h,2);l(C,{title:"DonutSwinConfig",local:"transformers.DonutSwinConfig",headingTag:"h2"});var _=e(C,2),N=n(_);r(N,{name:"class transformers.DonutSwinConfig",anchor:"transformers.DonutSwinConfig",source:"https://github.com/huggingface/transformers/blob/vr_51549/src/transformers/models/donut/configuration_donut_swin.py#L24",parameters:[{name:"transformers_version",val:": str | None = None"},{name:"architectures",val:": list[str] | None = None"},{name:"output_hidden_states",val:": bool | None = False"},{name:"return_dict",val:": bool | None = True"},{name:"dtype",val:": str | torch.dtype | None = None"},{name:"chunk_size_feed_forward",val:": int = 0"},{name:"is_encoder_decoder",val:": bool = False"},{name:"id2label",val:": dict[int, str] | dict[str, str] | None = None"},{name:"label2id",val:": dict[str, int] | dict[str, str] | None = None"},{name:"problem_type",val:": Literal['regression', 'single_label_classification', 'multi_label_classification'] | None = None"},{name:"image_size",val:": int | list[int] | tuple[int, int] = 224"},{name:"patch_size",val:": int | list[int] | tuple[int, int] = 4"},{name:"num_channels",val:": int = 3"},{name:"embed_dim",val:": int = 96"},{name:"depths",val:": list[int] | tuple[int, ...] = (2, 2, 6, 2)"},{name:"num_heads",val:": list[int] | tuple[int, ...] = (3, 6, 12, 24)"},{name:"window_size",val:": int = 7"},{name:"mlp_ratio",val:": float = 4.0"},{name:"qkv_bias",val:": bool = True"},{name:"hidden_dropout_prob",val:": float | int = 0.0"},{name:"attention_probs_dropout_prob",val:": float | int = 0.0"},{name:"drop_path_rate",val:": float | int = 0.1"},{name:"hidden_act",val:": str = 'gelu'"},{name:"use_absolute_embeddings",val:": bool = False"},{name:"initializer_range",val:": float = 0.02"},{name:"layer_norm_eps",val:": float = 1e-05"}],parametersDescription:[{anchor:"transformers.DonutSwinConfig.image_size",description:`<strong>image_size</strong> (<code>Union[int, list[int], tuple[int, int]]</code>, <em>optional</em>, defaults to <code>224</code>) &#x2014;
The size (resolution) of each image.`,name:"image_size"},{anchor:"transformers.DonutSwinConfig.patch_size",description:`<strong>patch_size</strong> (<code>Union[int, list[int], tuple[int, int]]</code>, <em>optional</em>, defaults to <code>4</code>) &#x2014;
The size (resolution) of each patch.`,name:"patch_size"},{anchor:"transformers.DonutSwinConfig.num_channels",description:`<strong>num_channels</strong> (<code>int</code>, <em>optional</em>, defaults to <code>3</code>) &#x2014;
The number of input channels.`,name:"num_channels"},{anchor:"transformers.DonutSwinConfig.embed_dim",description:`<strong>embed_dim</strong> (<code>int</code>, <em>optional</em>, defaults to <code>96</code>) &#x2014;
Dimensionality of the embeddings and hidden states.`,name:"embed_dim"},{anchor:"transformers.DonutSwinConfig.depths",description:`<strong>depths</strong> (<code>Union[list[int], tuple[int, ...]]</code>, <em>optional</em>, defaults to <code>(2, 2, 6, 2)</code>) &#x2014;
Depth of each layer in the Transformer.`,name:"depths"},{anchor:"transformers.DonutSwinConfig.num_heads",description:`<strong>num_heads</strong> (<code>Union[list[int], tuple[int, ...]]</code>, <em>optional</em>, defaults to <code>(3, 6, 12, 24)</code>) &#x2014;
Number of attention heads for each attention layer in the Transformer decoder.`,name:"num_heads"},{anchor:"transformers.DonutSwinConfig.window_size",description:`<strong>window_size</strong> (<code>int</code>, <em>optional</em>, defaults to 7) &#x2014;
Size of windows.`,name:"window_size"},{anchor:"transformers.DonutSwinConfig.mlp_ratio",description:`<strong>mlp_ratio</strong> (<code>float</code>, <em>optional</em>, defaults to <code>4.0</code>) &#x2014;
Ratio of the MLP hidden dim to the embedding dim.`,name:"mlp_ratio"},{anchor:"transformers.DonutSwinConfig.qkv_bias",description:`<strong>qkv_bias</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
Whether to add a bias to the queries, keys and values.`,name:"qkv_bias"},{anchor:"transformers.DonutSwinConfig.hidden_dropout_prob",description:`<strong>hidden_dropout_prob</strong> (<code>Union[float, int]</code>, <em>optional</em>, defaults to <code>0.0</code>) &#x2014;
The dropout probability for all fully connected layers in the embeddings, encoder, and pooler.`,name:"hidden_dropout_prob"},{anchor:"transformers.DonutSwinConfig.attention_probs_dropout_prob",description:`<strong>attention_probs_dropout_prob</strong> (<code>Union[float, int]</code>, <em>optional</em>, defaults to <code>0.0</code>) &#x2014;
The dropout ratio for the attention probabilities.`,name:"attention_probs_dropout_prob"},{anchor:"transformers.DonutSwinConfig.drop_path_rate",description:`<strong>drop_path_rate</strong> (<code>Union[float, int]</code>, <em>optional</em>, defaults to <code>0.1</code>) &#x2014;
Drop path rate for the patch fusion.`,name:"drop_path_rate"},{anchor:"transformers.DonutSwinConfig.hidden_act",description:`<strong>hidden_act</strong> (<code>str</code>, <em>optional</em>, defaults to <code>gelu</code>) &#x2014;
The non-linear activation function (function or string) in the decoder. For example, <code>&quot;gelu&quot;</code>,
<code>&quot;relu&quot;</code>, <code>&quot;silu&quot;</code>, etc.`,name:"hidden_act"},{anchor:"transformers.DonutSwinConfig.use_absolute_embeddings",description:`<strong>use_absolute_embeddings</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>) &#x2014;
Whether to use absolute position embeddings.`,name:"use_absolute_embeddings"},{anchor:"transformers.DonutSwinConfig.initializer_range",description:`<strong>initializer_range</strong> (<code>float</code>, <em>optional</em>, defaults to <code>0.02</code>) &#x2014;
The standard deviation of the truncated_normal_initializer for initializing all weight matrices.`,name:"initializer_range"},{anchor:"transformers.DonutSwinConfig.layer_norm_eps",description:`<strong>layer_norm_eps</strong> (<code>float</code>, <em>optional</em>, defaults to <code>1e-05</code>) &#x2014;
The epsilon used by the layer normalization layers.`,name:"layer_norm_eps"}]});var pe=e(N,6);te(pe,{anchor:"transformers.DonutSwinConfig.example",children:(o,a)=>{var s=ae(),m=e(g(s),2);c(m,{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMERvbnV0U3dpbkNvbmZpZyUyQyUyMERvbnV0U3dpbk1vZGVsJTBBJTBBJTIzJTIwSW5pdGlhbGl6aW5nJTIwYSUyMERvbnV0JTIwbmF2ZXItY2xvdmEtaXglMkZkb251dC1iYXNlJTIwc3R5bGUlMjBjb25maWd1cmF0aW9uJTBBY29uZmlndXJhdGlvbiUyMCUzRCUyMERvbnV0U3dpbkNvbmZpZygpJTBBJTBBJTIzJTIwUmFuZG9tbHklMjBpbml0aWFsaXppbmclMjBhJTIwbW9kZWwlMjBmcm9tJTIwdGhlJTIwbmF2ZXItY2xvdmEtaXglMkZkb251dC1iYXNlJTIwc3R5bGUlMjBjb25maWd1cmF0aW9uJTBBbW9kZWwlMjAlM0QlMjBEb251dFN3aW5Nb2RlbChjb25maWd1cmF0aW9uKSUwQSUwQSUyMyUyMEFjY2Vzc2luZyUyMHRoZSUyMG1vZGVsJTIwY29uZmlndXJhdGlvbiUwQWNvbmZpZ3VyYXRpb24lMjAlM0QlMjBtb2RlbC5jb25maWc=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> DonutSwinConfig, DonutSwinModel
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># Initializing a Donut naver-clova-ix/donut-base style configuration</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>configuration = DonutSwinConfig()
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># Randomly initializing a model from the naver-clova-ix/donut-base style configuration</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>model = DonutSwinModel(configuration)
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># Accessing the model configuration</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>configuration = model.config`,lang:"python",wrap:!1}),i(o,s)},$$slots:{default:!0}}),t(_);var P=e(_,2);l(P,{title:"DonutImageProcessor",local:"transformers.DonutImageProcessor",headingTag:"h2"});var b=e(P,2),B=n(b);r(B,{name:"class transformers.DonutImageProcessor",anchor:"transformers.DonutImageProcessor",source:"https://github.com/huggingface/transformers/blob/vr_51549/src/transformers/models/donut/image_processing_donut.py#L46",parameters:[{name:"**kwargs",val:": *<class 'transformers.models.donut.image_processing_donut.DonutImageProcessorKwargs'>"}],parametersDescription:[{anchor:"transformers.DonutImageProcessor.do_convert_rgb",description:`<strong>do_convert_rgb</strong> (<code>bool</code>, <em>kwargs</em>, <em>optional</em>) &#x2014;
Whether to convert the image to RGB.`,name:"do_convert_rgb"},{anchor:"transformers.DonutImageProcessor.do_resize",description:`<strong>do_resize</strong> (<code>bool</code>, <em>kwargs</em>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
Whether to resize the image.`,name:"do_resize"},{anchor:"transformers.DonutImageProcessor.size",description:`<strong>size</strong> (<code>Annotated[int | list[int] | tuple[int, ...] | dict[str, int] | None, None]</code>, <em>kwargs</em>, defaults to <code>{&apos;height&apos; -- 2560, &apos;width&apos;: 1920}</code>):
Describes the maximum input dimensions to the model.`,name:"size"},{anchor:"transformers.DonutImageProcessor.default_to_square",description:`<strong>default_to_square</strong> (<code>bool</code>, <em>kwargs</em>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
Whether to default to a square image when resizing, if size is an int.`,name:"default_to_square"},{anchor:"transformers.DonutImageProcessor.crop_size",description:`<strong>crop_size</strong> (<code>Annotated[int | list[int] | tuple[int, ...] | dict[str, int] | None, None]</code>, <em>kwargs</em>) &#x2014;
Size of the output image after applying <code>center_crop</code>.`,name:"crop_size"},{anchor:"transformers.DonutImageProcessor.resample",description:`<strong>resample</strong> (<code>Annotated[Union[int, PILImageResampling, NoneType], None]</code>, <em>kwargs</em>, defaults to <code>2</code>) &#x2014;
Resampling filter to use if resizing the image. This can be one of the enum <code>PILImageResampling</code>. Only
has an effect if <code>do_resize</code> is set to <code>True</code>.`,name:"resample"},{anchor:"transformers.DonutImageProcessor.do_rescale",description:`<strong>do_rescale</strong> (<code>bool</code>, <em>kwargs</em>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
Whether to rescale the image.`,name:"do_rescale"},{anchor:"transformers.DonutImageProcessor.rescale_factor",description:`<strong>rescale_factor</strong> (<code>float</code>, <em>kwargs</em>, <em>optional</em>, defaults to <code>0.00392156862745098</code>) &#x2014;
Rescale factor to rescale the image by if <code>do_rescale</code> is set to <code>True</code>.`,name:"rescale_factor"},{anchor:"transformers.DonutImageProcessor.do_normalize",description:`<strong>do_normalize</strong> (<code>bool</code>, <em>kwargs</em>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
Whether to normalize the image.`,name:"do_normalize"},{anchor:"transformers.DonutImageProcessor.image_mean",description:`<strong>image_mean</strong> (<code>Union[float, list[float], tuple[float, ...]]</code>, <em>kwargs</em>, <em>optional</em>, defaults to <code>[0.5, 0.5, 0.5]</code>) &#x2014;
Image mean to use for normalization. Only has an effect if <code>do_normalize</code> is set to <code>True</code>.`,name:"image_mean"},{anchor:"transformers.DonutImageProcessor.image_std",description:`<strong>image_std</strong> (<code>Union[float, list[float], tuple[float, ...]]</code>, <em>kwargs</em>, <em>optional</em>, defaults to <code>[0.5, 0.5, 0.5]</code>) &#x2014;
Image standard deviation to use for normalization. Only has an effect if <code>do_normalize</code> is set to
<code>True</code>.`,name:"image_std"},{anchor:"transformers.DonutImageProcessor.do_pad",description:`<strong>do_pad</strong> (<code>bool</code>, <em>kwargs</em>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
Whether to pad the image. Padding is done either to the largest size in the batch
or to a fixed square size per image. The exact padding strategy depends on the model.`,name:"do_pad"},{anchor:"transformers.DonutImageProcessor.pad_size",description:`<strong>pad_size</strong> (<code>Annotated[int | list[int] | tuple[int, ...] | dict[str, int] | None, None]</code>, <em>kwargs</em>) &#x2014;
The size in <code>{&quot;height&quot;: int, &quot;width&quot; int}</code> to pad the images to. Must be larger than any image size
provided for preprocessing. If <code>pad_size</code> is not provided, images will be padded to the largest
height and width in the batch. Applied only when <code>do_pad=True.</code>`,name:"pad_size"},{anchor:"transformers.DonutImageProcessor.do_center_crop",description:`<strong>do_center_crop</strong> (<code>bool</code>, <em>kwargs</em>, <em>optional</em>) &#x2014;
Whether to center crop the image.`,name:"do_center_crop"},{anchor:"transformers.DonutImageProcessor.data_format",description:`<strong>data_format</strong> (<code>Union[str, ~image_utils.ChannelDimension]</code>, <em>kwargs</em>, <em>optional</em>) &#x2014;
Only <code>ChannelDimension.FIRST</code> is supported. Added for compatibility with slow processors.`,name:"data_format"},{anchor:"transformers.DonutImageProcessor.input_data_format",description:`<strong>input_data_format</strong> (<code>Union[str, ~image_utils.ChannelDimension]</code>, <em>kwargs</em>, <em>optional</em>) &#x2014;
The channel dimension format for the input image. If unset, the channel dimension format is inferred
from the input image. Can be one of:
<ul>
<li><code>&quot;channels_first&quot;</code> or <code>ChannelDimension.FIRST</code>: image in (num_channels, height, width) format.</li>
<li><code>&quot;channels_last&quot;</code> or <code>ChannelDimension.LAST</code>: image in (height, width, num_channels) format.</li>
<li><code>&quot;none&quot;</code> or <code>ChannelDimension.NONE</code>: image in (height, width) format.</li>
</ul>`,name:"input_data_format"},{anchor:"transformers.DonutImageProcessor.device",description:`<strong>device</strong> (<code>Annotated[Union[str, torch.device, NoneType], None]</code>, <em>kwargs</em>) &#x2014;
The device to process the videos on. If unset, the device is inferred from the input videos.`,name:"device"},{anchor:"transformers.DonutImageProcessor.return_tensors",description:`<strong>return_tensors</strong> (<code>Annotated[str | ~utils.generic.TensorType | None, None]</code>, <em>kwargs</em>) &#x2014;
Returns stacked tensors if set to <code>&apos;pt&apos;</code>, otherwise returns a list of tensors.`,name:"return_tensors"},{anchor:"transformers.DonutImageProcessor.disable_grouping",description:`<strong>disable_grouping</strong> (<code>bool</code>, <em>kwargs</em>, <em>optional</em>) &#x2014;
Whether to disable grouping of images by size to process them individually and not in batches.
If None, will be set to True if the images are on CPU, and False otherwise. This choice is based on
empirical observations, as detailed here: <a href="https://github.com/huggingface/transformers/pull/38157" rel="nofollow">https://github.com/huggingface/transformers/pull/38157</a>`,name:"disable_grouping"},{anchor:"transformers.DonutImageProcessor.image_seq_length",description:`<strong>image_seq_length</strong> (<code>int</code>, <em>kwargs</em>, <em>optional</em>) &#x2014;
The number of image tokens to be used for each image in the input.
Added for backward compatibility but this should be set as a processor attribute in future models.`,name:"image_seq_length"},{anchor:"transformers.DonutImageProcessor.do_thumbnail",description:`<strong>do_thumbnail</strong> (<code>bool</code>, <em>kwargs</em>, <em>optional</em>, defaults to <code>self.do_thumbnail</code>) &#x2014;
Whether to resize the image using thumbnail method.`,name:"do_thumbnail"},{anchor:"transformers.DonutImageProcessor.do_align_long_axis",description:`<strong>do_align_long_axis</strong> (<code>bool</code>, <em>kwargs</em>, <em>optional</em>, defaults to <code>self.do_align_long_axis</code>) &#x2014;
Whether to align the long axis of the image with the long axis of <code>size</code> by rotating by 90 degrees.`,name:"do_align_long_axis"}]});var V=e(B,4),ge=n(V);r(ge,{name:"preprocess",anchor:"transformers.DonutImageProcessor.preprocess",source:"https://github.com/huggingface/transformers/blob/vr_51549/src/transformers/models/donut/image_processing_donut.py#L70",parameters:[{name:"images",val:": typing.Union[ForwardRef('PIL.Image.Image'), numpy.ndarray, ForwardRef('torch.Tensor'), list['PIL.Image.Image'], list[numpy.ndarray], list['torch.Tensor']]"},{name:"**kwargs",val:": *<class 'transformers.models.donut.image_processing_donut.DonutImageProcessorKwargs'>"}],parametersDescription:[{anchor:"transformers.DonutImageProcessor.preprocess.images",description:`<strong>images</strong> (<code>Union[PIL.Image.Image, numpy.ndarray, torch.Tensor, list[PIL.Image.Image], list[numpy.ndarray], list[torch.Tensor]]</code>) &#x2014;
Image to preprocess. Expects a single or batch of images with pixel values ranging from 0 to 255. If
passing in images with pixel values between 0 and 1, set <code>do_rescale=False</code>.`,name:"images"},{anchor:"transformers.DonutImageProcessor.preprocess.do_convert_rgb",description:`<strong>do_convert_rgb</strong> (<code>bool</code>, <em>kwargs</em>, <em>optional</em>) &#x2014;
Whether to convert the image to RGB.`,name:"do_convert_rgb"},{anchor:"transformers.DonutImageProcessor.preprocess.do_resize",description:`<strong>do_resize</strong> (<code>bool</code>, <em>kwargs</em>, <em>optional</em>) &#x2014;
Whether to resize the image.`,name:"do_resize"},{anchor:"transformers.DonutImageProcessor.preprocess.size",description:`<strong>size</strong> (<code>Annotated[int | list[int] | tuple[int, ...] | dict[str, int] | None, None]</code>, <em>kwargs</em>) &#x2014;
Describes the maximum input dimensions to the model.`,name:"size"},{anchor:"transformers.DonutImageProcessor.preprocess.default_to_square",description:`<strong>default_to_square</strong> (<code>bool</code>, <em>kwargs</em>, <em>optional</em>) &#x2014;
Whether to default to a square image when resizing, if size is an int.`,name:"default_to_square"},{anchor:"transformers.DonutImageProcessor.preprocess.crop_size",description:`<strong>crop_size</strong> (<code>Annotated[int | list[int] | tuple[int, ...] | dict[str, int] | None, None]</code>, <em>kwargs</em>) &#x2014;
Size of the output image after applying <code>center_crop</code>.`,name:"crop_size"},{anchor:"transformers.DonutImageProcessor.preprocess.resample",description:`<strong>resample</strong> (<code>Annotated[Union[int, PILImageResampling, NoneType], None]</code>, <em>kwargs</em>) &#x2014;
Resampling filter to use if resizing the image. This can be one of the enum <code>PILImageResampling</code>. Only
has an effect if <code>do_resize</code> is set to <code>True</code>.`,name:"resample"},{anchor:"transformers.DonutImageProcessor.preprocess.do_rescale",description:`<strong>do_rescale</strong> (<code>bool</code>, <em>kwargs</em>, <em>optional</em>) &#x2014;
Whether to rescale the image.`,name:"do_rescale"},{anchor:"transformers.DonutImageProcessor.preprocess.rescale_factor",description:`<strong>rescale_factor</strong> (<code>float</code>, <em>kwargs</em>, <em>optional</em>) &#x2014;
Rescale factor to rescale the image by if <code>do_rescale</code> is set to <code>True</code>.`,name:"rescale_factor"},{anchor:"transformers.DonutImageProcessor.preprocess.do_normalize",description:`<strong>do_normalize</strong> (<code>bool</code>, <em>kwargs</em>, <em>optional</em>) &#x2014;
Whether to normalize the image.`,name:"do_normalize"},{anchor:"transformers.DonutImageProcessor.preprocess.image_mean",description:`<strong>image_mean</strong> (<code>Union[float, list[float], tuple[float, ...]]</code>, <em>kwargs</em>, <em>optional</em>) &#x2014;
Image mean to use for normalization. Only has an effect if <code>do_normalize</code> is set to <code>True</code>.`,name:"image_mean"},{anchor:"transformers.DonutImageProcessor.preprocess.image_std",description:`<strong>image_std</strong> (<code>Union[float, list[float], tuple[float, ...]]</code>, <em>kwargs</em>, <em>optional</em>) &#x2014;
Image standard deviation to use for normalization. Only has an effect if <code>do_normalize</code> is set to
<code>True</code>.`,name:"image_std"},{anchor:"transformers.DonutImageProcessor.preprocess.do_pad",description:`<strong>do_pad</strong> (<code>bool</code>, <em>kwargs</em>, <em>optional</em>) &#x2014;
Whether to pad the image. Padding is done either to the largest size in the batch
or to a fixed square size per image. The exact padding strategy depends on the model.`,name:"do_pad"},{anchor:"transformers.DonutImageProcessor.preprocess.pad_size",description:`<strong>pad_size</strong> (<code>Annotated[int | list[int] | tuple[int, ...] | dict[str, int] | None, None]</code>, <em>kwargs</em>) &#x2014;
The size in <code>{&quot;height&quot;: int, &quot;width&quot; int}</code> to pad the images to. Must be larger than any image size
provided for preprocessing. If <code>pad_size</code> is not provided, images will be padded to the largest
height and width in the batch. Applied only when <code>do_pad=True.</code>`,name:"pad_size"},{anchor:"transformers.DonutImageProcessor.preprocess.do_center_crop",description:`<strong>do_center_crop</strong> (<code>bool</code>, <em>kwargs</em>, <em>optional</em>) &#x2014;
Whether to center crop the image.`,name:"do_center_crop"},{anchor:"transformers.DonutImageProcessor.preprocess.data_format",description:`<strong>data_format</strong> (<code>Union[str, ~image_utils.ChannelDimension]</code>, <em>kwargs</em>, <em>optional</em>) &#x2014;
Only <code>ChannelDimension.FIRST</code> is supported. Added for compatibility with slow processors.`,name:"data_format"},{anchor:"transformers.DonutImageProcessor.preprocess.input_data_format",description:`<strong>input_data_format</strong> (<code>Union[str, ~image_utils.ChannelDimension]</code>, <em>kwargs</em>, <em>optional</em>) &#x2014;
The channel dimension format for the input image. If unset, the channel dimension format is inferred
from the input image. Can be one of:
<ul>
<li><code>&quot;channels_first&quot;</code> or <code>ChannelDimension.FIRST</code>: image in (num_channels, height, width) format.</li>
<li><code>&quot;channels_last&quot;</code> or <code>ChannelDimension.LAST</code>: image in (height, width, num_channels) format.</li>
<li><code>&quot;none&quot;</code> or <code>ChannelDimension.NONE</code>: image in (height, width) format.</li>
</ul>`,name:"input_data_format"},{anchor:"transformers.DonutImageProcessor.preprocess.device",description:`<strong>device</strong> (<code>Annotated[Union[str, torch.device, NoneType], None]</code>, <em>kwargs</em>) &#x2014;
The device to process the videos on. If unset, the device is inferred from the input videos.`,name:"device"},{anchor:"transformers.DonutImageProcessor.preprocess.return_tensors",description:`<strong>return_tensors</strong> (<code>Annotated[str | ~utils.generic.TensorType | None, None]</code>, <em>kwargs</em>) &#x2014;
Returns stacked tensors if set to <code>&apos;pt&apos;</code>, otherwise returns a list of tensors.`,name:"return_tensors"},{anchor:"transformers.DonutImageProcessor.preprocess.disable_grouping",description:`<strong>disable_grouping</strong> (<code>bool</code>, <em>kwargs</em>, <em>optional</em>) &#x2014;
Whether to disable grouping of images by size to process them individually and not in batches.
If None, will be set to True if the images are on CPU, and False otherwise. This choice is based on
empirical observations, as detailed here: <a href="https://github.com/huggingface/transformers/pull/38157" rel="nofollow">https://github.com/huggingface/transformers/pull/38157</a>`,name:"disable_grouping"},{anchor:"transformers.DonutImageProcessor.preprocess.image_seq_length",description:`<strong>image_seq_length</strong> (<code>int</code>, <em>kwargs</em>, <em>optional</em>) &#x2014;
The number of image tokens to be used for each image in the input.
Added for backward compatibility but this should be set as a processor attribute in future models.`,name:"image_seq_length"},{anchor:"transformers.DonutImageProcessor.preprocess.do_thumbnail",description:`<strong>do_thumbnail</strong> (<code>bool</code>, <em>kwargs</em>, <em>optional</em>, defaults to <code>self.do_thumbnail</code>) &#x2014;
Whether to resize the image using thumbnail method.`,name:"do_thumbnail"},{anchor:"transformers.DonutImageProcessor.preprocess.do_align_long_axis",description:`<strong>do_align_long_axis</strong> (<code>bool</code>, <em>kwargs</em>, <em>optional</em>, defaults to <code>self.do_align_long_axis</code>) &#x2014;
Whether to align the long axis of the image with the long axis of <code>size</code> by rotating by 90 degrees.`,name:"do_align_long_axis"}],returnDescription:`
<ul>
<li><strong>data</strong> (<code>dict</code>) — Dictionary of lists/arrays/tensors returned by the <strong>call</strong> method (‘pixel_values’, etc.).</li>
<li><strong>tensor_type</strong> (<code>Union[None, str, TensorType]</code>, <em>optional</em>) — You can give a tensor_type here to convert the lists of integers in PyTorch/Numpy Tensors at
initialization.</li>
</ul>
`,returnType:`
<p><code>~image_processing_base.BatchFeature</code></p>
`}),t(V),t(b);var G=e(b,2);l(G,{title:"DonutImageProcessorPil",local:"transformers.DonutImageProcessorPil",headingTag:"h2"});var y=e(G,2),q=n(y);r(q,{name:"class transformers.DonutImageProcessorPil",anchor:"transformers.DonutImageProcessorPil",source:"https://github.com/huggingface/transformers/blob/vr_51549/src/transformers/models/donut/image_processing_pil_donut.py#L46",parameters:[{name:"**kwargs",val:": *<class 'transformers.models.donut.image_processing_pil_donut.DonutImageProcessorKwargs'>"}],parametersDescription:[{anchor:"transformers.DonutImageProcessorPil.do_convert_rgb",description:`<strong>do_convert_rgb</strong> (<code>bool</code>, <em>kwargs</em>, <em>optional</em>) &#x2014;
Whether to convert the image to RGB.`,name:"do_convert_rgb"},{anchor:"transformers.DonutImageProcessorPil.do_resize",description:`<strong>do_resize</strong> (<code>bool</code>, <em>kwargs</em>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
Whether to resize the image.`,name:"do_resize"},{anchor:"transformers.DonutImageProcessorPil.size",description:`<strong>size</strong> (<code>Annotated[int | list[int] | tuple[int, ...] | dict[str, int] | None, None]</code>, <em>kwargs</em>, defaults to <code>{&apos;height&apos; -- 2560, &apos;width&apos;: 1920}</code>):
Describes the maximum input dimensions to the model.`,name:"size"},{anchor:"transformers.DonutImageProcessorPil.default_to_square",description:`<strong>default_to_square</strong> (<code>bool</code>, <em>kwargs</em>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
Whether to default to a square image when resizing, if size is an int.`,name:"default_to_square"},{anchor:"transformers.DonutImageProcessorPil.crop_size",description:`<strong>crop_size</strong> (<code>Annotated[int | list[int] | tuple[int, ...] | dict[str, int] | None, None]</code>, <em>kwargs</em>) &#x2014;
Size of the output image after applying <code>center_crop</code>.`,name:"crop_size"},{anchor:"transformers.DonutImageProcessorPil.resample",description:`<strong>resample</strong> (<code>Annotated[Union[int, PILImageResampling, NoneType], None]</code>, <em>kwargs</em>, defaults to <code>2</code>) &#x2014;
Resampling filter to use if resizing the image. This can be one of the enum <code>PILImageResampling</code>. Only
has an effect if <code>do_resize</code> is set to <code>True</code>.`,name:"resample"},{anchor:"transformers.DonutImageProcessorPil.do_rescale",description:`<strong>do_rescale</strong> (<code>bool</code>, <em>kwargs</em>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
Whether to rescale the image.`,name:"do_rescale"},{anchor:"transformers.DonutImageProcessorPil.rescale_factor",description:`<strong>rescale_factor</strong> (<code>float</code>, <em>kwargs</em>, <em>optional</em>, defaults to <code>0.00392156862745098</code>) &#x2014;
Rescale factor to rescale the image by if <code>do_rescale</code> is set to <code>True</code>.`,name:"rescale_factor"},{anchor:"transformers.DonutImageProcessorPil.do_normalize",description:`<strong>do_normalize</strong> (<code>bool</code>, <em>kwargs</em>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
Whether to normalize the image.`,name:"do_normalize"},{anchor:"transformers.DonutImageProcessorPil.image_mean",description:`<strong>image_mean</strong> (<code>Union[float, list[float], tuple[float, ...]]</code>, <em>kwargs</em>, <em>optional</em>, defaults to <code>[0.5, 0.5, 0.5]</code>) &#x2014;
Image mean to use for normalization. Only has an effect if <code>do_normalize</code> is set to <code>True</code>.`,name:"image_mean"},{anchor:"transformers.DonutImageProcessorPil.image_std",description:`<strong>image_std</strong> (<code>Union[float, list[float], tuple[float, ...]]</code>, <em>kwargs</em>, <em>optional</em>, defaults to <code>[0.5, 0.5, 0.5]</code>) &#x2014;
Image standard deviation to use for normalization. Only has an effect if <code>do_normalize</code> is set to
<code>True</code>.`,name:"image_std"},{anchor:"transformers.DonutImageProcessorPil.do_pad",description:`<strong>do_pad</strong> (<code>bool</code>, <em>kwargs</em>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
Whether to pad the image. Padding is done either to the largest size in the batch
or to a fixed square size per image. The exact padding strategy depends on the model.`,name:"do_pad"},{anchor:"transformers.DonutImageProcessorPil.pad_size",description:`<strong>pad_size</strong> (<code>Annotated[int | list[int] | tuple[int, ...] | dict[str, int] | None, None]</code>, <em>kwargs</em>) &#x2014;
The size in <code>{&quot;height&quot;: int, &quot;width&quot; int}</code> to pad the images to. Must be larger than any image size
provided for preprocessing. If <code>pad_size</code> is not provided, images will be padded to the largest
height and width in the batch. Applied only when <code>do_pad=True.</code>`,name:"pad_size"},{anchor:"transformers.DonutImageProcessorPil.do_center_crop",description:`<strong>do_center_crop</strong> (<code>bool</code>, <em>kwargs</em>, <em>optional</em>) &#x2014;
Whether to center crop the image.`,name:"do_center_crop"},{anchor:"transformers.DonutImageProcessorPil.data_format",description:`<strong>data_format</strong> (<code>Union[str, ~image_utils.ChannelDimension]</code>, <em>kwargs</em>, <em>optional</em>) &#x2014;
Only <code>ChannelDimension.FIRST</code> is supported. Added for compatibility with slow processors.`,name:"data_format"},{anchor:"transformers.DonutImageProcessorPil.input_data_format",description:`<strong>input_data_format</strong> (<code>Union[str, ~image_utils.ChannelDimension]</code>, <em>kwargs</em>, <em>optional</em>) &#x2014;
The channel dimension format for the input image. If unset, the channel dimension format is inferred
from the input image. Can be one of:
<ul>
<li><code>&quot;channels_first&quot;</code> or <code>ChannelDimension.FIRST</code>: image in (num_channels, height, width) format.</li>
<li><code>&quot;channels_last&quot;</code> or <code>ChannelDimension.LAST</code>: image in (height, width, num_channels) format.</li>
<li><code>&quot;none&quot;</code> or <code>ChannelDimension.NONE</code>: image in (height, width) format.</li>
</ul>`,name:"input_data_format"},{anchor:"transformers.DonutImageProcessorPil.device",description:`<strong>device</strong> (<code>Annotated[Union[str, torch.device, NoneType], None]</code>, <em>kwargs</em>) &#x2014;
The device to process the videos on. If unset, the device is inferred from the input videos.`,name:"device"},{anchor:"transformers.DonutImageProcessorPil.return_tensors",description:`<strong>return_tensors</strong> (<code>Annotated[str | ~utils.generic.TensorType | None, None]</code>, <em>kwargs</em>) &#x2014;
Returns stacked tensors if set to <code>&apos;pt&apos;</code>, otherwise returns a list of tensors.`,name:"return_tensors"},{anchor:"transformers.DonutImageProcessorPil.disable_grouping",description:`<strong>disable_grouping</strong> (<code>bool</code>, <em>kwargs</em>, <em>optional</em>) &#x2014;
Whether to disable grouping of images by size to process them individually and not in batches.
If None, will be set to True if the images are on CPU, and False otherwise. This choice is based on
empirical observations, as detailed here: <a href="https://github.com/huggingface/transformers/pull/38157" rel="nofollow">https://github.com/huggingface/transformers/pull/38157</a>`,name:"disable_grouping"},{anchor:"transformers.DonutImageProcessorPil.image_seq_length",description:`<strong>image_seq_length</strong> (<code>int</code>, <em>kwargs</em>, <em>optional</em>) &#x2014;
The number of image tokens to be used for each image in the input.
Added for backward compatibility but this should be set as a processor attribute in future models.`,name:"image_seq_length"},{anchor:"transformers.DonutImageProcessorPil.do_thumbnail",description:`<strong>do_thumbnail</strong> (<code>bool</code>, <em>kwargs</em>, <em>optional</em>, defaults to <code>self.do_thumbnail</code>) &#x2014;
Whether to resize the image using thumbnail method.`,name:"do_thumbnail"},{anchor:"transformers.DonutImageProcessorPil.do_align_long_axis",description:`<strong>do_align_long_axis</strong> (<code>bool</code>, <em>kwargs</em>, <em>optional</em>, defaults to <code>self.do_align_long_axis</code>) &#x2014;
Whether to align the long axis of the image with the long axis of <code>size</code> by rotating by 90 degrees.`,name:"do_align_long_axis"}]});var F=e(q,4),ue=n(F);r(ue,{name:"preprocess",anchor:"transformers.DonutImageProcessorPil.preprocess",source:"https://github.com/huggingface/transformers/blob/vr_51549/src/transformers/models/donut/image_processing_pil_donut.py#L70",parameters:[{name:"images",val:": typing.Union[ForwardRef('PIL.Image.Image'), numpy.ndarray, ForwardRef('torch.Tensor'), list['PIL.Image.Image'], list[numpy.ndarray], list['torch.Tensor']]"},{name:"**kwargs",val:": *<class 'transformers.models.donut.image_processing_pil_donut.DonutImageProcessorKwargs'>"}],parametersDescription:[{anchor:"transformers.DonutImageProcessorPil.preprocess.images",description:`<strong>images</strong> (<code>Union[PIL.Image.Image, numpy.ndarray, torch.Tensor, list[PIL.Image.Image], list[numpy.ndarray], list[torch.Tensor]]</code>) &#x2014;
Image to preprocess. Expects a single or batch of images with pixel values ranging from 0 to 255. If
passing in images with pixel values between 0 and 1, set <code>do_rescale=False</code>.`,name:"images"},{anchor:"transformers.DonutImageProcessorPil.preprocess.do_convert_rgb",description:`<strong>do_convert_rgb</strong> (<code>bool</code>, <em>kwargs</em>, <em>optional</em>) &#x2014;
Whether to convert the image to RGB.`,name:"do_convert_rgb"},{anchor:"transformers.DonutImageProcessorPil.preprocess.do_resize",description:`<strong>do_resize</strong> (<code>bool</code>, <em>kwargs</em>, <em>optional</em>) &#x2014;
Whether to resize the image.`,name:"do_resize"},{anchor:"transformers.DonutImageProcessorPil.preprocess.size",description:`<strong>size</strong> (<code>Annotated[int | list[int] | tuple[int, ...] | dict[str, int] | None, None]</code>, <em>kwargs</em>) &#x2014;
Describes the maximum input dimensions to the model.`,name:"size"},{anchor:"transformers.DonutImageProcessorPil.preprocess.default_to_square",description:`<strong>default_to_square</strong> (<code>bool</code>, <em>kwargs</em>, <em>optional</em>) &#x2014;
Whether to default to a square image when resizing, if size is an int.`,name:"default_to_square"},{anchor:"transformers.DonutImageProcessorPil.preprocess.crop_size",description:`<strong>crop_size</strong> (<code>Annotated[int | list[int] | tuple[int, ...] | dict[str, int] | None, None]</code>, <em>kwargs</em>) &#x2014;
Size of the output image after applying <code>center_crop</code>.`,name:"crop_size"},{anchor:"transformers.DonutImageProcessorPil.preprocess.resample",description:`<strong>resample</strong> (<code>Annotated[Union[int, PILImageResampling, NoneType], None]</code>, <em>kwargs</em>) &#x2014;
Resampling filter to use if resizing the image. This can be one of the enum <code>PILImageResampling</code>. Only
has an effect if <code>do_resize</code> is set to <code>True</code>.`,name:"resample"},{anchor:"transformers.DonutImageProcessorPil.preprocess.do_rescale",description:`<strong>do_rescale</strong> (<code>bool</code>, <em>kwargs</em>, <em>optional</em>) &#x2014;
Whether to rescale the image.`,name:"do_rescale"},{anchor:"transformers.DonutImageProcessorPil.preprocess.rescale_factor",description:`<strong>rescale_factor</strong> (<code>float</code>, <em>kwargs</em>, <em>optional</em>) &#x2014;
Rescale factor to rescale the image by if <code>do_rescale</code> is set to <code>True</code>.`,name:"rescale_factor"},{anchor:"transformers.DonutImageProcessorPil.preprocess.do_normalize",description:`<strong>do_normalize</strong> (<code>bool</code>, <em>kwargs</em>, <em>optional</em>) &#x2014;
Whether to normalize the image.`,name:"do_normalize"},{anchor:"transformers.DonutImageProcessorPil.preprocess.image_mean",description:`<strong>image_mean</strong> (<code>Union[float, list[float], tuple[float, ...]]</code>, <em>kwargs</em>, <em>optional</em>) &#x2014;
Image mean to use for normalization. Only has an effect if <code>do_normalize</code> is set to <code>True</code>.`,name:"image_mean"},{anchor:"transformers.DonutImageProcessorPil.preprocess.image_std",description:`<strong>image_std</strong> (<code>Union[float, list[float], tuple[float, ...]]</code>, <em>kwargs</em>, <em>optional</em>) &#x2014;
Image standard deviation to use for normalization. Only has an effect if <code>do_normalize</code> is set to
<code>True</code>.`,name:"image_std"},{anchor:"transformers.DonutImageProcessorPil.preprocess.do_pad",description:`<strong>do_pad</strong> (<code>bool</code>, <em>kwargs</em>, <em>optional</em>) &#x2014;
Whether to pad the image. Padding is done either to the largest size in the batch
or to a fixed square size per image. The exact padding strategy depends on the model.`,name:"do_pad"},{anchor:"transformers.DonutImageProcessorPil.preprocess.pad_size",description:`<strong>pad_size</strong> (<code>Annotated[int | list[int] | tuple[int, ...] | dict[str, int] | None, None]</code>, <em>kwargs</em>) &#x2014;
The size in <code>{&quot;height&quot;: int, &quot;width&quot; int}</code> to pad the images to. Must be larger than any image size
provided for preprocessing. If <code>pad_size</code> is not provided, images will be padded to the largest
height and width in the batch. Applied only when <code>do_pad=True.</code>`,name:"pad_size"},{anchor:"transformers.DonutImageProcessorPil.preprocess.do_center_crop",description:`<strong>do_center_crop</strong> (<code>bool</code>, <em>kwargs</em>, <em>optional</em>) &#x2014;
Whether to center crop the image.`,name:"do_center_crop"},{anchor:"transformers.DonutImageProcessorPil.preprocess.data_format",description:`<strong>data_format</strong> (<code>Union[str, ~image_utils.ChannelDimension]</code>, <em>kwargs</em>, <em>optional</em>) &#x2014;
Only <code>ChannelDimension.FIRST</code> is supported. Added for compatibility with slow processors.`,name:"data_format"},{anchor:"transformers.DonutImageProcessorPil.preprocess.input_data_format",description:`<strong>input_data_format</strong> (<code>Union[str, ~image_utils.ChannelDimension]</code>, <em>kwargs</em>, <em>optional</em>) &#x2014;
The channel dimension format for the input image. If unset, the channel dimension format is inferred
from the input image. Can be one of:
<ul>
<li><code>&quot;channels_first&quot;</code> or <code>ChannelDimension.FIRST</code>: image in (num_channels, height, width) format.</li>
<li><code>&quot;channels_last&quot;</code> or <code>ChannelDimension.LAST</code>: image in (height, width, num_channels) format.</li>
<li><code>&quot;none&quot;</code> or <code>ChannelDimension.NONE</code>: image in (height, width) format.</li>
</ul>`,name:"input_data_format"},{anchor:"transformers.DonutImageProcessorPil.preprocess.device",description:`<strong>device</strong> (<code>Annotated[Union[str, torch.device, NoneType], None]</code>, <em>kwargs</em>) &#x2014;
The device to process the videos on. If unset, the device is inferred from the input videos.`,name:"device"},{anchor:"transformers.DonutImageProcessorPil.preprocess.return_tensors",description:`<strong>return_tensors</strong> (<code>Annotated[str | ~utils.generic.TensorType | None, None]</code>, <em>kwargs</em>) &#x2014;
Returns stacked tensors if set to <code>&apos;pt&apos;</code>, otherwise returns a list of tensors.`,name:"return_tensors"},{anchor:"transformers.DonutImageProcessorPil.preprocess.disable_grouping",description:`<strong>disable_grouping</strong> (<code>bool</code>, <em>kwargs</em>, <em>optional</em>) &#x2014;
Whether to disable grouping of images by size to process them individually and not in batches.
If None, will be set to True if the images are on CPU, and False otherwise. This choice is based on
empirical observations, as detailed here: <a href="https://github.com/huggingface/transformers/pull/38157" rel="nofollow">https://github.com/huggingface/transformers/pull/38157</a>`,name:"disable_grouping"},{anchor:"transformers.DonutImageProcessorPil.preprocess.image_seq_length",description:`<strong>image_seq_length</strong> (<code>int</code>, <em>kwargs</em>, <em>optional</em>) &#x2014;
The number of image tokens to be used for each image in the input.
Added for backward compatibility but this should be set as a processor attribute in future models.`,name:"image_seq_length"},{anchor:"transformers.DonutImageProcessorPil.preprocess.do_thumbnail",description:`<strong>do_thumbnail</strong> (<code>bool</code>, <em>kwargs</em>, <em>optional</em>, defaults to <code>self.do_thumbnail</code>) &#x2014;
Whether to resize the image using thumbnail method.`,name:"do_thumbnail"},{anchor:"transformers.DonutImageProcessorPil.preprocess.do_align_long_axis",description:`<strong>do_align_long_axis</strong> (<code>bool</code>, <em>kwargs</em>, <em>optional</em>, defaults to <code>self.do_align_long_axis</code>) &#x2014;
Whether to align the long axis of the image with the long axis of <code>size</code> by rotating by 90 degrees.`,name:"do_align_long_axis"}],returnDescription:`
<ul>
<li><strong>data</strong> (<code>dict</code>) — Dictionary of lists/arrays/tensors returned by the <strong>call</strong> method (‘pixel_values’, etc.).</li>
<li><strong>tensor_type</strong> (<code>Union[None, str, TensorType]</code>, <em>optional</em>) — You can give a tensor_type here to convert the lists of integers in PyTorch/Numpy Tensors at
initialization.</li>
</ul>
`,returnType:`
<p><code>~image_processing_base.BatchFeature</code></p>
`}),t(F),t(y);var X=e(y,2);l(X,{title:"DonutProcessor",local:"transformers.DonutProcessor",headingTag:"h2"});var w=e(X,2),S=n(w);r(S,{name:"class transformers.DonutProcessor",anchor:"transformers.DonutProcessor",source:"https://github.com/huggingface/transformers/blob/vr_51549/src/transformers/models/donut/processing_donut.py#L31",parameters:[{name:"image_processor",val:" = None"},{name:"tokenizer",val:" = None"},{name:"**kwargs",val:""}],parametersDescription:[{anchor:"transformers.DonutProcessor.image_processor",description:`<strong>image_processor</strong> (<code>image_processor_class</code>) &#x2014;
The image processor is a required input.`,name:"image_processor"},{anchor:"transformers.DonutProcessor.tokenizer",description:`<strong>tokenizer</strong> (<code>tokenizer_class</code>) &#x2014;
The tokenizer is a required input.`,name:"tokenizer"}]});var M=e(S,6),he=n(M);r(he,{name:"__call__",anchor:"transformers.DonutProcessor.__call__",source:"https://github.com/huggingface/transformers/blob/vr_51549/src/transformers/models/donut/processing_donut.py#L35",parameters:[{name:"images",val:": typing.Union[ForwardRef('PIL.Image.Image'), numpy.ndarray, ForwardRef('torch.Tensor'), list['PIL.Image.Image'], list[numpy.ndarray], list['torch.Tensor'], NoneType] = None"},{name:"text",val:": str | list[str] | list[list[str]] | None = None"},{name:"**kwargs",val:": *<class 'transformers.processing_utils.ProcessingKwargs'>"}],parametersDescription:[{anchor:"transformers.DonutProcessor.__call__.images",description:`<strong>images</strong> (<code>Union[PIL.Image.Image, numpy.ndarray, torch.Tensor, list[PIL.Image.Image], list[numpy.ndarray], list[torch.Tensor]]</code>, <em>optional</em>) &#x2014;
Image to preprocess. Expects a single or batch of images with pixel values ranging from 0 to 255. If
passing in images with pixel values between 0 and 1, set <code>do_rescale=False</code>.`,name:"images"},{anchor:"transformers.DonutProcessor.__call__.text",description:`<strong>text</strong> (<code>Union[str, list[str], list[list[str]]]</code>, <em>optional</em>) &#x2014;
The sequence or batch of sequences to be encoded. Each sequence can be a string or a list of strings
(pretokenized string). If you pass a pretokenized input, set <code>is_split_into_words=True</code> to avoid ambiguity with batched inputs.`,name:"text"},{anchor:"transformers.DonutProcessor.__call__.return_mm_token_type_ids",description:`<strong>return_mm_token_type_ids</strong> (<code>bool</code>, <em>kwargs</em>) &#x2014;
Whether to return multimodal token type ids indicating multimodal placeholder token positions.`,name:"return_mm_token_type_ids"},{anchor:"transformers.DonutProcessor.__call__.return_text_replacement_offsets",description:`<strong>return_text_replacement_offsets</strong> (<code>bool</code>, <em>kwargs</em>) &#x2014;
Whether to return character offsets for each multimodal placeholder and its replacement.`,name:"return_text_replacement_offsets"},{anchor:"transformers.DonutProcessor.__call__.return_tensors",description:`<strong>return_tensors</strong> (<code>str</code> or <a href="/docs/transformers/pr_51549/en/internal/file_utils#transformers.TensorType">TensorType</a>, <em>optional</em>) &#x2014;
If set, will return tensors of a particular framework. Acceptable values are:
<ul>
<li><code>&apos;pt&apos;</code>: Return PyTorch <code>torch.Tensor</code> objects.</li>
<li><code>&apos;np&apos;</code>: Return NumPy <code>np.ndarray</code> objects.</li>
</ul>`,name:"return_tensors"},{anchor:"transformers.DonutProcessor.__call__.*kwargs",description:`*<strong>*kwargs</strong> (<a href="/docs/transformers/pr_51549/en/main_classes/processors#transformers.ProcessingKwargs">ProcessingKwargs</a>, <em>optional</em>) &#x2014;
Additional processing options for each modality (text, images, videos, audio). Model-specific parameters
are listed above; see the TypedDict class for the complete list of supported arguments.`,name:"*kwargs"}]}),t(M);var T=e(M,2),Y=n(T);r(Y,{name:"from_pretrained",anchor:"transformers.DonutProcessor.from_pretrained",source:"https://github.com/huggingface/transformers/blob/vr_51549/src/transformers/processing_utils.py#L1915",parameters:[{name:"pretrained_model_name_or_path",val:": str | os.PathLike"},{name:"cache_dir",val:": str | os.PathLike | None = None"},{name:"force_download",val:": bool = False"},{name:"local_files_only",val:": bool = False"},{name:"token",val:": str | bool | None = None"},{name:"revision",val:": str = 'main'"},{name:"**kwargs",val:""}],parametersDescription:[{anchor:"transformers.DonutProcessor.from_pretrained.pretrained_model_name_or_path",description:`<strong>pretrained_model_name_or_path</strong> (<code>str</code> or <code>os.PathLike</code>) &#x2014;
This can be either:
<ul>
<li>a string, the <em>model id</em> of a pretrained feature_extractor hosted inside a model repo on
huggingface.co.</li>
<li>a path to a <em>directory</em> containing a feature extractor file saved using the
<a href="/docs/transformers/pr_51549/en/main_classes/feature_extractor#transformers.FeatureExtractionMixin.save_pretrained">save_pretrained()</a> method, e.g., <code>./my_model_directory/</code>.</li>
<li>a path to a saved feature extractor JSON <em>file</em>, e.g.,
<code>./my_model_directory/preprocessor_config.json</code>.</li>
</ul>`,name:"pretrained_model_name_or_path"},{anchor:"transformers.DonutProcessor.from_pretrained.*kwargs",description:`*<strong>*kwargs</strong> &#x2014;
Additional keyword arguments passed along to both
<a href="/docs/transformers/pr_51549/en/main_classes/feature_extractor#transformers.FeatureExtractionMixin.from_pretrained">from_pretrained()</a> and
<code>~tokenization_utils_base.PreTrainedTokenizer.from_pretrained</code>.`,name:"*kwargs"}]});var fe=e(Y,4);p(fe,{children:(o,a)=>{var s=Pe();i(o,s)},$$slots:{default:!0}}),t(T);var v=e(T,2),Q=n(v);r(Q,{name:"save_pretrained",anchor:"transformers.DonutProcessor.save_pretrained",source:"https://github.com/huggingface/transformers/blob/vr_51549/src/transformers/processing_utils.py#L1248",parameters:[{name:"save_directory",val:""},{name:"push_to_hub",val:": bool = False"},{name:"**kwargs",val:""}],parametersDescription:[{anchor:"transformers.DonutProcessor.save_pretrained.save_directory",description:`<strong>save_directory</strong> (<code>str</code> or <code>os.PathLike</code>) &#x2014;
Directory where the feature extractor JSON file and the tokenizer files will be saved (directory will
be created if it does not exist).`,name:"save_directory"},{anchor:"transformers.DonutProcessor.save_pretrained.push_to_hub",description:`<strong>push_to_hub</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>) &#x2014;
Whether or not to push your model to the Hugging Face model hub after saving it. You can specify the
repository you want to push to with <code>repo_id</code> (will default to the name of <code>save_directory</code> in your
namespace).`,name:"push_to_hub"},{anchor:"transformers.DonutProcessor.save_pretrained.kwargs",description:`<strong>kwargs</strong> (<code>dict[str, Any]</code>, <em>optional</em>) &#x2014;
Additional key word arguments passed along to the <a href="/docs/transformers/pr_51549/en/main_classes/model#transformers.utils.PushToHubMixin.push_to_hub">push_to_hub()</a> method.`,name:"kwargs"}]});var _e=e(Q,4);p(_e,{children:(o,a)=>{var s=Be();i(o,s)},$$slots:{default:!0}}),t(v);var I=e(v,2),be=n(I);r(be,{name:"batch_decode",anchor:"transformers.DonutProcessor.batch_decode",source:"https://github.com/huggingface/transformers/blob/vr_51549/src/transformers/processing_utils.py#L2160",parameters:[{name:"*args",val:""},{name:"**kwargs",val:""}]}),u(2),t(I);var E=e(I,2),ye=n(E);r(ye,{name:"decode",anchor:"transformers.DonutProcessor.decode",source:"https://github.com/huggingface/transformers/blob/vr_51549/src/transformers/processing_utils.py#L2169",parameters:[{name:"*args",val:""},{name:"**kwargs",val:""}]}),u(2),t(E),t(w);var A=e(w,2);l(A,{title:"DonutSwinModel",local:"transformers.DonutSwinModel",headingTag:"h2"});var J=e(A,2),H=n(J);r(H,{name:"class transformers.DonutSwinModel",anchor:"transformers.DonutSwinModel",source:"https://github.com/huggingface/transformers/blob/vr_51549/src/transformers/models/donut/modeling_donut_swin.py#L784",parameters:[{name:"config",val:": DonutSwinConfig"},{name:"add_pooling_layer",val:" = True"},{name:"use_mask_token",val:" = False"}],parametersDescription:[{anchor:"transformers.DonutSwinModel.config",description:`<strong>config</strong> (<a href="/docs/transformers/pr_51549/en/model_doc/donut#transformers.DonutSwinConfig">DonutSwinConfig</a>) &#x2014;
Model configuration class with all the parameters of the model. Initializing with a config file does not
load the weights associated with the model, only the configuration. Check out the
<a href="/docs/transformers/pr_51549/en/main_classes/model#transformers.PreTrainedModel.from_pretrained">from_pretrained()</a> method to load the model weights.`,name:"config"},{anchor:"transformers.DonutSwinModel.add_pooling_layer",description:`<strong>add_pooling_layer</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
Whether to add a pooling layer`,name:"add_pooling_layer"},{anchor:"transformers.DonutSwinModel.use_mask_token",description:`<strong>use_mask_token</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>) &#x2014;
Whether to use a mask token for masked image modeling.`,name:"use_mask_token"}]});var L=e(H,8),K=n(L);r(K,{name:"forward",anchor:"transformers.DonutSwinModel.forward",source:"https://github.com/huggingface/transformers/blob/vr_51549/src/transformers/models/donut/modeling_donut_swin.py#L808",parameters:[{name:"pixel_values",val:": typing.Optional[torch.Tensor] = None"},{name:"bool_masked_pos",val:": typing.Optional[torch.BoolTensor] = None"},{name:"output_attentions",val:": bool | None = None"},{name:"output_hidden_states",val:": bool | None = None"},{name:"interpolate_pos_encoding",val:": bool = False"},{name:"return_dict",val:": bool | None = None"},{name:"**kwargs",val:""}],parametersDescription:[{anchor:"transformers.DonutSwinModel.forward.pixel_values",description:`<strong>pixel_values</strong> (<code>torch.Tensor</code> of shape <code>(batch_size, num_channels, image_size, image_size)</code>, <em>optional</em>) &#x2014;
The tensors corresponding to the input images. Pixel values can be obtained using
<a href="/docs/transformers/pr_51549/en/model_doc/donut#transformers.DonutImageProcessor">DonutImageProcessor</a>. See <a href="/docs/transformers/pr_51549/en/model_doc/molmo2#transformers.Molmo2ImageProcessor.__call__">DonutImageProcessor.<strong>call</strong>()</a> for details (<code>processor_class</code> uses
<a href="/docs/transformers/pr_51549/en/model_doc/donut#transformers.DonutImageProcessor">DonutImageProcessor</a> for processing images).`,name:"pixel_values"},{anchor:"transformers.DonutSwinModel.forward.bool_masked_pos",description:`<strong>bool_masked_pos</strong> (<code>torch.BoolTensor</code> of shape <code>(batch_size, num_patches)</code>) &#x2014;
Boolean masked positions. Indicates which patches are masked (1) and which aren&#x2019;t (0).`,name:"bool_masked_pos"},{anchor:"transformers.DonutSwinModel.forward.output_attentions",description:`<strong>output_attentions</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return the attentions tensors of all attention layers. See <code>attentions</code> under returned
tensors for more detail.`,name:"output_attentions"},{anchor:"transformers.DonutSwinModel.forward.output_hidden_states",description:`<strong>output_hidden_states</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return the hidden states of all layers. See <code>hidden_states</code> under returned tensors for
more detail.`,name:"output_hidden_states"},{anchor:"transformers.DonutSwinModel.forward.interpolate_pos_encoding",description:`<strong>interpolate_pos_encoding</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>) &#x2014;
Whether to interpolate the pre-trained position encodings.`,name:"interpolate_pos_encoding"},{anchor:"transformers.DonutSwinModel.forward.return_dict",description:`<strong>return_dict</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return a <a href="/docs/transformers/pr_51549/en/main_classes/output#transformers.utils.ModelOutput">ModelOutput</a> instead of a plain tuple.`,name:"return_dict"}],returnDescription:`
<p>A <code>DonutSwinModelOutput</code> or a tuple of
<code>torch.Tensor</code> (if <code>return_dict=False</code> is passed or when <code>config.return_dict=False</code>) comprising various
elements depending on the configuration (<a
href="/docs/transformers/pr_51549/en/model_doc/donut#transformers.DonutSwinConfig"
>DonutSwinConfig</a>) and inputs.</p>
`,returnType:`
<p><code>DonutSwinModelOutput</code> or <code>tuple(torch.Tensor)</code></p>
`});var we=e(K,4);p(we,{children:(o,a)=>{var s=ie();i(o,s)},$$slots:{default:!0}}),u(2),t(L),t(J);var O=e(J,2);l(O,{title:"DonutSwinForImageClassification",local:"transformers.DonutSwinForImageClassification",headingTag:"h2"});var U=e(O,2),$=n(U);r($,{name:"class transformers.DonutSwinForImageClassification",anchor:"transformers.DonutSwinForImageClassification",source:"https://github.com/huggingface/transformers/blob/vr_51549/src/transformers/models/donut/modeling_donut_swin.py#L880",parameters:[{name:"config",val:": DonutSwinConfig"}],parametersDescription:[{anchor:"transformers.DonutSwinForImageClassification.config",description:`<strong>config</strong> (<a href="/docs/transformers/pr_51549/en/model_doc/donut#transformers.DonutSwinConfig">DonutSwinConfig</a>) &#x2014;
Model configuration class with all the parameters of the model. Initializing with a config file does not
load the weights associated with the model, only the configuration. Check out the
<a href="/docs/transformers/pr_51549/en/main_classes/model#transformers.PreTrainedModel.from_pretrained">from_pretrained()</a> method to load the model weights.`,name:"config"}]});var ee=e($,4);p(ee,{children:(o,a)=>{var s=Ve();i(o,s)},$$slots:{default:!0}});var oe=e(ee,6),se=n(oe);r(se,{name:"forward",anchor:"transformers.DonutSwinForImageClassification.forward",source:"https://github.com/huggingface/transformers/blob/vr_51549/src/transformers/models/donut/modeling_donut_swin.py#L895",parameters:[{name:"pixel_values",val:": typing.Optional[torch.Tensor] = None"},{name:"labels",val:": typing.Optional[torch.LongTensor] = None"},{name:"output_attentions",val:": bool | None = None"},{name:"output_hidden_states",val:": bool | None = None"},{name:"interpolate_pos_encoding",val:": bool = False"},{name:"return_dict",val:": bool | None = None"},{name:"**kwargs",val:""}],parametersDescription:[{anchor:"transformers.DonutSwinForImageClassification.forward.pixel_values",description:`<strong>pixel_values</strong> (<code>torch.Tensor</code> of shape <code>(batch_size, num_channels, image_size, image_size)</code>, <em>optional</em>) &#x2014;
The tensors corresponding to the input images. Pixel values can be obtained using
<a href="/docs/transformers/pr_51549/en/model_doc/donut#transformers.DonutImageProcessor">DonutImageProcessor</a>. See <a href="/docs/transformers/pr_51549/en/model_doc/molmo2#transformers.Molmo2ImageProcessor.__call__">DonutImageProcessor.<strong>call</strong>()</a> for details (<code>processor_class</code> uses
<a href="/docs/transformers/pr_51549/en/model_doc/donut#transformers.DonutImageProcessor">DonutImageProcessor</a> for processing images).`,name:"pixel_values"},{anchor:"transformers.DonutSwinForImageClassification.forward.labels",description:`<strong>labels</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size,)</code>, <em>optional</em>) &#x2014;
Labels for computing the image classification/regression loss. Indices should be in <code>[0, ..., config.num_labels - 1]</code>. If <code>config.num_labels == 1</code> a regression loss is computed (Mean-Square loss), If
<code>config.num_labels &gt; 1</code> a classification loss is computed (Cross-Entropy).`,name:"labels"},{anchor:"transformers.DonutSwinForImageClassification.forward.output_attentions",description:`<strong>output_attentions</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return the attentions tensors of all attention layers. See <code>attentions</code> under returned
tensors for more detail.`,name:"output_attentions"},{anchor:"transformers.DonutSwinForImageClassification.forward.output_hidden_states",description:`<strong>output_hidden_states</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return the hidden states of all layers. See <code>hidden_states</code> under returned tensors for
more detail.`,name:"output_hidden_states"},{anchor:"transformers.DonutSwinForImageClassification.forward.interpolate_pos_encoding",description:`<strong>interpolate_pos_encoding</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>) &#x2014;
Whether to interpolate the pre-trained position encodings.`,name:"interpolate_pos_encoding"},{anchor:"transformers.DonutSwinForImageClassification.forward.return_dict",description:`<strong>return_dict</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return a <a href="/docs/transformers/pr_51549/en/main_classes/output#transformers.utils.ModelOutput">ModelOutput</a> instead of a plain tuple.`,name:"return_dict"}],returnDescription:`
<p>A <code>DonutSwinImageClassifierOutput</code> or a tuple of
<code>torch.Tensor</code> (if <code>return_dict=False</code> is passed or when <code>config.return_dict=False</code>) comprising various
elements depending on the configuration (<a
href="/docs/transformers/pr_51549/en/model_doc/donut#transformers.DonutSwinConfig"
>DonutSwinConfig</a>) and inputs.</p>
`,returnType:`
<p><code>DonutSwinImageClassifierOutput</code> or <code>tuple(torch.Tensor)</code></p>
`});var ne=e(se,4);p(ne,{children:(o,a)=>{var s=ie();i(o,s)},$$slots:{default:!0}});var Me=e(ne,4);te(Me,{anchor:"transformers.DonutSwinForImageClassification.forward.example",children:(o,a)=>{var s=ae(),m=e(g(s),2);c(m,{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9JbWFnZVByb2Nlc3NvciUyQyUyMERvbnV0U3dpbkZvckltYWdlQ2xhc3NpZmljYXRpb24lMEFpbXBvcnQlMjB0b3JjaCUwQWZyb20lMjBkYXRhc2V0cyUyMGltcG9ydCUyMGxvYWRfZGF0YXNldCUwQSUwQWRhdGFzZXQlMjAlM0QlMjBsb2FkX2RhdGFzZXQoJTIyaHVnZ2luZ2ZhY2UlMkZjYXRzLWltYWdlJTIyKSUwQWltYWdlJTIwJTNEJTIwZGF0YXNldCU1QiUyMnRlc3QlMjIlNUQlNUIlMjJpbWFnZSUyMiU1RCU1QjAlNUQlMEElMEFpbWFnZV9wcm9jZXNzb3IlMjAlM0QlMjBBdXRvSW1hZ2VQcm9jZXNzb3IuZnJvbV9wcmV0cmFpbmVkKCUyMm5hdmVyLWNsb3ZhLWl4JTJGZG9udXQtYmFzZSUyMiklMEFtb2RlbCUyMCUzRCUyMERvbnV0U3dpbkZvckltYWdlQ2xhc3NpZmljYXRpb24uZnJvbV9wcmV0cmFpbmVkKCUyMm5hdmVyLWNsb3ZhLWl4JTJGZG9udXQtYmFzZSUyMiklMEElMEFpbnB1dHMlMjAlM0QlMjBpbWFnZV9wcm9jZXNzb3IoaW1hZ2UlMkMlMjByZXR1cm5fdGVuc29ycyUzRCUyMnB0JTIyKSUwQSUwQXdpdGglMjB0b3JjaC5ub19ncmFkKCklM0ElMEElMjAlMjAlMjAlMjBsb2dpdHMlMjAlM0QlMjBtb2RlbCgqKmlucHV0cykubG9naXRzJTBBJTBBJTIzJTIwbW9kZWwlMjBwcmVkaWN0cyUyMG9uZSUyMG9mJTIwdGhlJTIwMTAwMCUyMEltYWdlTmV0JTIwY2xhc3NlcyUwQXByZWRpY3RlZF9sYWJlbCUyMCUzRCUyMGxvZ2l0cy5hcmdtYXgoLTEpLml0ZW0oKSUwQXByaW50KG1vZGVsLmNvbmZpZy5pZDJsYWJlbCU1QnByZWRpY3RlZF9sYWJlbCU1RCk=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoImageProcessor, DonutSwinForImageClassification
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> torch
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> datasets <span class="hljs-keyword">import</span> load_dataset
<span class="hljs-meta">&gt;&gt;&gt; </span>dataset = load_dataset(<span class="hljs-string">&quot;huggingface/cats-image&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>image = dataset[<span class="hljs-string">&quot;test&quot;</span>][<span class="hljs-string">&quot;image&quot;</span>][<span class="hljs-number">0</span>]
<span class="hljs-meta">&gt;&gt;&gt; </span>image_processor = AutoImageProcessor.from_pretrained(<span class="hljs-string">&quot;naver-clova-ix/donut-base&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>model = DonutSwinForImageClassification.from_pretrained(<span class="hljs-string">&quot;naver-clova-ix/donut-base&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>inputs = image_processor(image, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">with</span> torch.no_grad():
<span class="hljs-meta">... </span> logits = model(**inputs).logits
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># model predicts one of the 1000 ImageNet classes</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>predicted_label = logits.argmax(-<span class="hljs-number">1</span>).item()
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-built_in">print</span>(model.config.id2label[predicted_label])
...`,lang:"python",wrap:!1}),i(o,s)},$$slots:{default:!0}}),t(oe),t(U);var Te=e(U,2);ze(Te,{source:"https://github.com/huggingface/transformers/blob/main/docs/source/en/model_doc/donut.md"}),u(2),i(le,j),Re()}export{Ee as component};

Xet Storage Details

Size:
99.9 kB
·
Xet hash:
03ba99cdd7e8e111539474d3dabf0f0f3189f4c07c5239588dca0f981daa0e93

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.