Instructions to use microsoft/trocr-base-stage1 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use microsoft/trocr-base-stage1 with Transformers:
# Use a pipeline as a high-level helper # Warning: Pipeline type "image-to-text" is no longer supported in transformers v5. # You must load the model directly (see below) or downgrade to v4.x with: # 'pip install "transformers<5.0.0' from transformers import pipeline pipe = pipeline("image-to-text", model="microsoft/trocr-base-stage1")# Load model directly from transformers import AutoTokenizer, AutoModelForMultimodalLM tokenizer = AutoTokenizer.from_pretrained("microsoft/trocr-base-stage1") model = AutoModelForMultimodalLM.from_pretrained("microsoft/trocr-base-stage1", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Fix code example
Browse files
README.md
CHANGED
|
@@ -36,10 +36,9 @@ processor = TrOCRProcessor.from_pretrained('microsoft/trocr-base-stage1')
|
|
| 36 |
model = VisionEncoderDecoderModel.from_pretrained('microsoft/trocr-base-stage1')
|
| 37 |
|
| 38 |
# training
|
| 39 |
-
pixel_values = processor(
|
| 40 |
-
|
| 41 |
-
outputs = model(pixel_values=pixel_values,
|
| 42 |
-
loss = outputs.loss
|
| 43 |
```
|
| 44 |
|
| 45 |
### BibTeX entry and citation info
|
|
|
|
| 36 |
model = VisionEncoderDecoderModel.from_pretrained('microsoft/trocr-base-stage1')
|
| 37 |
|
| 38 |
# training
|
| 39 |
+
pixel_values = processor(image, return_tensors="pt").pixel_values # Batch size 1
|
| 40 |
+
decoder_input_ids = torch.tensor([[model.config.decoder.decoder_start_token_id]])
|
| 41 |
+
outputs = model(pixel_values=pixel_values, decoder_input_ids=decoder_input_ids)
|
|
|
|
| 42 |
```
|
| 43 |
|
| 44 |
### BibTeX entry and citation info
|