Spaces:
Sleeping
Sleeping
Rename cord_inference.py to inference.py
Browse files
cord_inference.py → inference.py
RENAMED
@@ -4,54 +4,12 @@ from transformers import LayoutLMv3TokenizerFast, LayoutLMv3Processor, LayoutLMv
|
|
4 |
from PIL import Image, ImageDraw, ImageFont
|
5 |
from utils import OCR, unnormalize_box
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
"B-MENU.PRICE",
|
14 |
-
"B-MENU.SUB.CNT",
|
15 |
-
"B-MENU.SUB.NM",
|
16 |
-
"B-MENU.SUB.PRICE",
|
17 |
-
"B-MENU.UNITPRICE",
|
18 |
-
"B-SUB_TOTAL.DISCOUNT_PRICE",
|
19 |
-
"B-SUB_TOTAL.ETC",
|
20 |
-
"B-SUB_TOTAL.SERVICE_PRICE",
|
21 |
-
"B-SUB_TOTAL.SUBTOTAL_PRICE",
|
22 |
-
"B-SUB_TOTAL.TAX_PRICE",
|
23 |
-
"B-TOTAL.CASHPRICE",
|
24 |
-
"B-TOTAL.CHANGEPRICE",
|
25 |
-
"B-TOTAL.CREDITCARDPRICE",
|
26 |
-
"B-TOTAL.MENUQTY_CNT",
|
27 |
-
"B-TOTAL.TOTAL_PRICE",
|
28 |
-
"I-MENU.CNT",
|
29 |
-
"I-MENU.DISCOUNTPRICE",
|
30 |
-
"I-MENU.NM",
|
31 |
-
"I-MENU.NUM",
|
32 |
-
"I-MENU.PRICE",
|
33 |
-
"I-MENU.SUB.CNT",
|
34 |
-
"I-MENU.SUB.NM",
|
35 |
-
"I-MENU.SUB.PRICE",
|
36 |
-
"I-MENU.UNITPRICE",
|
37 |
-
"I-SUB_TOTAL.DISCOUNT_PRICE",
|
38 |
-
"I-SUB_TOTAL.ETC",
|
39 |
-
"I-SUB_TOTAL.SERVICE_PRICE",
|
40 |
-
"I-SUB_TOTAL.SUBTOTAL_PRICE",
|
41 |
-
"I-SUB_TOTAL.TAX_PRICE",
|
42 |
-
"I-TOTAL.CASHPRICE",
|
43 |
-
"I-TOTAL.CHANGEPRICE",
|
44 |
-
"I-TOTAL.CREDITCARDPRICE",
|
45 |
-
"I-TOTAL.MENUQTY_CNT",
|
46 |
-
"I-TOTAL.TOTAL_PRICE"
|
47 |
-
]
|
48 |
-
|
49 |
-
id2label = dict(enumerate(label_list))
|
50 |
-
label2id = {v: k for k, v in enumerate(label_list)}
|
51 |
-
|
52 |
-
tokenizer = LayoutLMv3TokenizerFast.from_pretrained("mp-02/layoutlmv3-finetuned-cord", apply_ocr=False)
|
53 |
-
processor = LayoutLMv3Processor.from_pretrained("mp-02/layoutlmv3-finetuned-cord", apply_ocr=False)
|
54 |
-
model = LayoutLMv3ForTokenClassification.from_pretrained("mp-02/layoutlmv3-finetuned-cord")
|
55 |
|
56 |
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
57 |
model.to(device)
|
|
|
4 |
from PIL import Image, ImageDraw, ImageFont
|
5 |
from utils import OCR, unnormalize_box
|
6 |
|
7 |
+
tokenizer = LayoutLMv3TokenizerFast.from_pretrained("mp-02/layoutlmv3-finetuned-cord-sroie", apply_ocr=False)
|
8 |
+
processor = LayoutLMv3Processor.from_pretrained("mp-02/layoutlmv3-finetuned-cord-sroie", apply_ocr=False)
|
9 |
+
model = LayoutLMv3ForTokenClassification.from_pretrained("mp-02/layoutlmv3-finetuned-cord-sroie")
|
10 |
+
|
11 |
+
id2label = model.config.id2label
|
12 |
+
label2id = model.config.label2id
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
15 |
model.to(device)
|