'LayoutLMv2Processor' object has no attribute 'image_processor' 
Author: andysingal
Pull request: no

### System Info

Colab Notebook


### Who can help?

@NielsRogge @amyeroberts 

### Information

- [X] The official example scripts
- [ ] My own modified scripts

### Tasks

- [ ] An officially supported task in the `examples` folder (such as GLUE/SQuAD, ...)
- [ ] My own task or dataset (give details below)

### Reproduction

Code:
https://huggingface.co/docs/transformers/v4.34.1/en/tasks/document_question_answering#preprocessing-document-images
```

!sudo apt update
!sudo apt install tesseract-ocr
!sudo apt install libtesseract-dev

! pip install Pillow
! pip install pytesseract

# !pip install git+https://github.com/huggingface/transformers.git@2ef774211733f0acf8d3415f9284c49ef219e991
# !pip install tensorflow
# !pip install h5py
# !pip install transformers

!pip install git+https://github.com/huggingface/transformers.git@2ef774211733f0acf8d3415f9284c49ef219e991 datasets
!pip install 'git+https://github.com/facebookresearch/detectron2.git'

from transformers import AutoProcessor
model_checkpoint="microsoft/layoutlmv2-base-uncased"
batch_size=4

processor=AutoProcessor.from_pretrained(model_checkpoint)

image_processor=processor.image_processor


def get_ocr_words_and_boxes(examples):
    images=[image.convert("RGB") for image in examples["image"]]
    encoded_inputs=image_processor(images)
    
    examples["image"]=encoded_inputs.pixel_values
    examples["words"]=encoded_inputs.words
    examples["boxes"]=encoded_inputs.boxes
    
    return examples

ERROR:
AttributeError                            Traceback (most recent call last)
[<ipython-input-14-914d2324f9c7>](https://localhost:8080/#) in <cell line: 1>()
----> 1 image_processor=processor.image_processor
      2 
      3 
      4 def get_ocr_words_and_boxes(examples):
      5     images=[image.convert("RGB") for image in examples["image"]]

AttributeError: 'LayoutLMv2Processor' object has no attribute 'image_processor'
```


### Expected behavior

running the model

Comments:
I believe the [preprocessor_config.json](https://huggingface.co/microsoft/layoutlmv2-base-uncased/blob/main/preprocessor_config.json) needs to be edited. Unfortunately I can't get detectron2 installed on my system right now, but I think this should do it:

```
{
  "apply_ocr": true,
  "do_resize": true,
  "image_processor_type": "LayoutLMv2ImageProcessor",
  "resample": 2,
  "size": 224
}
```

@andysingal Maybe you can give it a try on your system. The file can be found in the model subdirectory of `~/.cache/huggingface/hub/`. See whether it works if you adjust it on your system. If it works you can click "contribute" on the [model page preprocessor_config.json](https://huggingface.co/microsoft/layoutlmv2-base-uncased/blob/main/preprocessor_config.json) and submit a fix.

Hi @andysingal, thanks for raising an issue! 

The problem is coming from the commit being used to install transformers. It's v4.16 which is before image processors were added. I suggest upgrading to the most recent version of transformers. 

Had the same issue today. 

Used paperspace notebook with preinstalled Transformer + NLP package. I guess there was an issue with the version so just using notebook with preinstall Pytorch package worked for me. Hope this can help.

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the [contributing guidelines](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md) are likely to be ignored.