mp-02 commited on
Commit
1655071
·
verified ·
1 Parent(s): 98c2996

Update cord_inference.py

Browse files
Files changed (1) hide show
  1. cord_inference.py +3 -44
cord_inference.py CHANGED
@@ -4,55 +4,14 @@ from transformers import LayoutLMv3TokenizerFast, LayoutLMv3Processor, LayoutLMv
4
  from PIL import Image, ImageDraw, ImageFont
5
  from utils import OCR, unnormalize_box
6
 
7
- label_list = [
8
- "O",
9
- "B-MENU.CNT",
10
- "B-MENU.DISCOUNTPRICE",
11
- "B-MENU.NM",
12
- "B-MENU.NUM",
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)
58
 
 
4
  from PIL import Image, ImageDraw, ImageFont
5
  from utils import OCR, unnormalize_box
6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
 
8
  tokenizer = LayoutLMv3TokenizerFast.from_pretrained("mp-02/layoutlmv3-finetuned-cord", apply_ocr=False)
9
  processor = LayoutLMv3Processor.from_pretrained("mp-02/layoutlmv3-finetuned-cord", apply_ocr=False)
10
  model = LayoutLMv3ForTokenClassification.from_pretrained("mp-02/layoutlmv3-finetuned-cord")
11
 
12
+ id2label = model.config.id2label
13
+ label2id = model.config.label2id
14
+
15
  device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
16
  model.to(device)
17