Update code example
This commit is contained in:
parent
cbb9551979
commit
bb14f6d89e
13
README.md
13
README.md
|
@ -23,7 +23,7 @@ You can use the raw model for optical character recognition (OCR) on single text
|
|||
Here is how to use this model in PyTorch:
|
||||
|
||||
```python
|
||||
from transformers import TrOCRProcessor, VisionEncoderDecoderModel, AutoFeatureExtractor, XLMRobertaTokenizer
|
||||
from transformers import TrOCRProcessor, VisionEncoderDecoderModel
|
||||
from PIL import Image
|
||||
import requests
|
||||
|
||||
|
@ -31,17 +31,12 @@ import requests
|
|||
url = 'https://fki.tic.heia-fr.ch/static/img/a01-122-02-00.jpg'
|
||||
image = Image.open(requests.get(url, stream=True).raw).convert("RGB")
|
||||
|
||||
# For the time being, TrOCRProcessor does not support the small models, so the following temporary solution can be adopted
|
||||
# processor = TrOCRProcessor.from_pretrained('microsoft/trocr-small-handwritten')
|
||||
feature_extractor = AutoFeatureExtractor.from_pretrained('microsoft/trocr-small-handwritten')
|
||||
tokenizer = XLMRobertaTokenizer.from_pretrained('microsoft/trocr-small-handwritten')
|
||||
processor = TrOCRProcessor.from_pretrained('microsoft/trocr-small-handwritten')
|
||||
model = VisionEncoderDecoderModel.from_pretrained('microsoft/trocr-small-handwritten')
|
||||
# pixel_values = processor(images=image, return_tensors="pt").pixel_values
|
||||
pixel_values = feature_extractor(images=image, return_tensors="pt").pixel_values
|
||||
pixel_values = processor(images=image, return_tensors="pt").pixel_values
|
||||
|
||||
generated_ids = model.generate(pixel_values)
|
||||
# generated_text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
||||
generated_text = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
||||
generated_text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
||||
```
|
||||
|
||||
### BibTeX entry and citation info
|
||||
|
|
Loading…
Reference in New Issue