class_docstr: Prepare document data for Document Classification.
  OCR (Optical character recognition) is applied to get the document texts and bounding boxes.
  Both texts and images will be processed.
class_docstr_tok: ["Prepare","document","data","for","Document","Classification",".","OCR","(","Optical","character","recognition",")","is","applied","to","get","the","document","texts","and","bounding","boxes",".","Both","texts","and","images","will","be","processed","."]
docstr: Parameters
  ----------
  model
      The model using this data processor.
  train_transform_types
      A list of image transforms used in training. Note that the transform order matters.
  val_transform_types
      A list of image transforms used in validation/test/prediction. Note that the transform order matters.
  norm_type
      How to normalize an image. We now support:
      - inception
          Normalize image by IMAGENET_INCEPTION_MEAN and IMAGENET_INCEPTION_STD from timm
      - imagenet
          Normalize image by IMAGENET_DEFAULT_MEAN and IMAGENET_DEFAULT_STD from timm
      - clip
          Normalize image by mean (0.48145466, 0.4578275, 0.40821073) and
          std (0.26862954, 0.26130258, 0.27577711), used for CLIP.
  size
      The width / height of a square image.
  text_max_len
      The max text length of tokenizer. Default: 512.
  missing_value_strategy
      How to deal with a missing document. We now support:
      - skip
          Skip this sample
      -zero
          Use a document image with zero pixels.
docstr_tok: ["Parameters","--","--","--","--","--","model","The","model","using","this","data","processor",".","train_transform_types","A","list","of","image","transforms","used","in","training",".","Note","that","the","transform","order","matters",".","val_transform_types","A","list","of","image","transforms","used","in","validation\/test\/prediction",".","Note","that","the","transform","order","matters",".","norm_type","How","to","normalize","an","image",".","We","now","support",":","-","inception","Normalize","image","by","IMAGENET_INCEPTION_MEAN","and","IMAGENET_INCEPTION_STD","from","timm","-","imagenet","Normalize","image","by","IMAGENET_DEFAULT_MEAN","and","IMAGENET_DEFAULT_STD","from","timm","-","clip","Normalize","image","by","mean","(","0.48145466",",","0.4578275",",","0.40821073",")","and","std","(","0.26862954",",","0.26130258",",","0.27577711",")",",","used","for","CLIP",".","size","The","width","\/","height","of","a","square","image",".","text_max_len","The","max","text","length","of","tokenizer",".","Default",":","512.","missing_value_strategy","How","to","deal","with","a","missing","document",".","We","now","support",":","-","skip","Skip","this","sample","-zero","Use","a","document","image","with","zero","pixels","."]
code: def __init__(
      self,
      model: nn.Module,
      train_transform_types: List[str],
      val_transform_types: List[str],
      norm_type: Optional[str] = None,
      size: Optional[int] = None,
      text_max_len: Optional[int] = 512,
      missing_value_strategy: Optional[str] = "zero",
  ):
      """
      Parameters
      ----------
      model
          The model using this data processor.
      train_transform_types
          A list of image transforms used in training. Note that the transform order matters.
      val_transform_types
          A list of image transforms used in validation/test/prediction. Note that the transform order matters.
      norm_type
          How to normalize an image. We now support:
          - inception
              Normalize image by IMAGENET_INCEPTION_MEAN and IMAGENET_INCEPTION_STD from timm
          - imagenet
              Normalize image by IMAGENET_DEFAULT_MEAN and IMAGENET_DEFAULT_STD from timm
          - clip
              Normalize image by mean (0.48145466, 0.4578275, 0.40821073) and
              std (0.26862954, 0.26130258, 0.27577711), used for CLIP.
      size
          The width / height of a square image.
      text_max_len
          The max text length of tokenizer. Default: 512.
      missing_value_strategy
          How to deal with a missing document. We now support:
          - skip
              Skip this sample
          -zero
              Use a document image with zero pixels.
      """
      self.prefix = model.prefix
      self.text_token_ids_key = model.text_token_ids_key
      self.text_attention_mask_key = model.text_attention_mask_key
      self.text_bbox_key = model.text_bbox_key
      self.text_segment_ids_key = model.text_segment_ids_key
      self.document_pixel_value_key = model.document_pixel_value_key
  
      # For document image processing.
      self.size = size
      self.train_transform_types = train_transform_types
      self.val_transform_types = val_transform_types
      self.mean, self.std = image_mean_std(norm_type)
      self.normalization = transforms.Normalize(self.mean, self.std)
      self.train_processor = construct_image_processor(
          size=self.size,
          normalization=self.normalization,
          image_transforms=self.train_transform_types,
      )
      self.val_processor = construct_image_processor(
          size=self.size,
          normalization=self.normalization,
          image_transforms=self.val_transform_types,
      )
  
      self.missing_value_strategy = missing_value_strategy
  
      # Store OCR results
      self.documents = {}
  
      # Whether only text is used (automatically detected).
      # If True, normal text foundation models (e.g., bert-base) can be used.
      self.is_text_only_flag = model.is_text_only_flag
  
      self.pad_token_box = [0, 0, 0, 0]  # cls box token
      self.sep_token_box = [1000, 1000, 1000, 1000]  # sep box token
  
      # For document text processing.
      # Disable tokenizer parallelism
      os.environ["TOKENIZERS_PARALLELISM"] = "false"
      self.tokenizer_name = model.tokenizer_name
      self.tokenizer = model.tokenizer
      if text_max_len is None or text_max_len <= 0:
          self.text_max_len = self.tokenizer.model_max_length
      else:
          if text_max_len < self.tokenizer.model_max_length:
              warnings.warn(
                  f"provided max length: {text_max_len} "
                  f"is smaller than {model.checkpoint_name}'s default: {self.tokenizer.model_max_length}"
              )
          self.text_max_len = min(
              text_max_len, self.tokenizer.model_max_length
          )
  
      self.tokenizer.model_max_length = self.text_max_len
  
imports: import logging
  import os
  import warnings
  from io import BytesIO
  from typing import Any, Dict, List, Optional, Union
  import numpy
  import PIL
  import pytesseract
  import torch
  from nptyping import NDArray
  from PIL import ImageFile
  from torch import nn
  from torchvision import transforms
  from ..constants import AUTOMM, BBOX, DOCUMENT_PDF
  from .collator import PadCollator, StackCollator
  from .utils import construct_image_processor, image_mean_std
label_desc: Use image node_id 1 to create a new DocumentProcessor object  with example: obj = DocumentProcessor(model, train_transform_types, val_transform_types, norm_type, size, text_max_len, missing_value_strategy)