Spaces:
Runtime error
Runtime error
Commit
·
17038e2
1
Parent(s):
0ffaebd
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,16 @@
|
|
| 1 |
-
import
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import LayoutLMv2Processor, LayoutLMv2ForTokenClassification
|
| 2 |
+
from PIL import Image
|
| 3 |
|
| 4 |
+
processor = LayoutLMv2Processor.from_pretrained("microsoft/layoutlmv2-base-uncased", revision="no_ocr")
|
| 5 |
+
model = LayoutLMv2ForTokenClassification.from_pretrained("microsoft/layoutlmv2-base-uncased")
|
| 6 |
+
|
| 7 |
+
image = Image.open("Labels-New\OriginalImages_cropped_ocr_results\IMG_1693.bmp").convert("RGB")
|
| 8 |
+
words = ["hello", "world"]
|
| 9 |
+
boxes = [[1, 2, 3, 4], [5, 6, 7, 8]] # make sure to normalize your bounding boxes
|
| 10 |
+
word_labels = [0, 1]
|
| 11 |
+
|
| 12 |
+
encoding = processor(image, words, boxes=boxes, word_labels=word_labels, return_tensors="pt")
|
| 13 |
+
|
| 14 |
+
outputs = model(**encoding)
|
| 15 |
+
loss = outputs.loss
|
| 16 |
+
logits = outputs.logits
|