mp-02 commited on
Commit
0a411ad
·
verified ·
1 Parent(s): 53d7087

Update cord_inference.py

Browse files
Files changed (1) hide show
  1. cord_inference.py +83 -3
cord_inference.py CHANGED
@@ -5,9 +5,89 @@ from PIL import Image, ImageDraw, ImageFont
5
  from utils import OCR, unnormalize_box
6
 
7
 
8
- labels = ["O", "B-MENU.NM", "B-MENU.NUM", "B-MENU.UNITPRICE", "B-MENU.CNT", "B-MENU.DISCOUNTPRICE", "B-MENU.PRICE", "B-MENU.ITEMSUBTOTAL", "B-MENU.SUB.NM", "B-MENU.SUB.UNITPRICE", "B-MENU.SUB.CNT", "B-MENU.SUB.PRICE", "B-MENU.SUB.ETC", "B-SUB_TOTAL.SUBTOTAL_PRICE", "B-SUB_TOTAL.DISCOUNT_PRICE", "B-SUB_TOTAL.SERVICE_PRICE", "B-SUB_TOTAL.OTHERSVC_PRICE", "B-SUB_TOTAL.TAX_PRICE", "B-TOTAL.TOTAL_PRICE", "B-TOTAL.CASHPRICE", "B-TOTAL.CHANGEPRICE", "B-TOTAL.CREDITCARDPRICE", "B-TOTAL.EMONEYPRICE", "B-TOTAL.MENUTYPE_CNT", "B-TOTAL.MENUQTY_CNT", "I-MENU.NM", "I-MENU.NUM", "I-MENU.UNITPRICE", "I-MENU.CNT", "I-MENU.DISCOUNTPRICE", "I-MENU.PRICE", "I-MENU.ITEMSUBTOTAL", "I-MENU.SUB.NM", "I-MENU.SUB.UNITPRICE", "I-MENU.SUB.CNT", "I-MENU.SUB.PRICE", "I-MENU.SUB.ETC", "I-SUB_TOTAL.SUBTOTAL_PRICE", "I-SUB_TOTAL.DISCOUNT_PRICE", "I-SUB_TOTAL.SERVICE_PRICE", "I-SUB_TOTAL.OTHERSVC_PRICE", "I-SUB_TOTAL.TAX_PRICE", "I-TOTAL.TOTAL_PRICE", "I-TOTAL.CASHPRICE", "I-TOTAL.CHANGEPRICE", "I-TOTAL.CREDITCARDPRICE", "I-TOTAL.EMONEYPRICE", "I-TOTAL.MENUTYPE_CNT", "I-TOTAL.MENUQTY_CNT"]
9
- id2label = {v: k for v, k in enumerate(labels)}
10
- label2id = {k: v for v, k in enumerate(labels)}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
  # nielsr/layoutlmv3-finetuned-cord
13
  tokenizer = LayoutLMv3TokenizerFast.from_pretrained("mp-02/layoutlmv3-finetuned-cord", apply_ocr=False)
 
5
  from utils import OCR, unnormalize_box
6
 
7
 
8
+ id2label: {
9
+ "0": "O",
10
+ "1": "B-MENU.CNT",
11
+ "2": "B-MENU.DISCOUNTPRICE",
12
+ "3": "B-MENU.NM",
13
+ "4": "B-MENU.NUM",
14
+ "5": "B-MENU.PRICE",
15
+ "6": "B-MENU.SUB.CNT",
16
+ "7": "B-MENU.SUB.NM",
17
+ "8": "B-MENU.SUB.PRICE",
18
+ "9": "B-MENU.UNITPRICE",
19
+ "10": "B-SUB_TOTAL.DISCOUNT_PRICE",
20
+ "11": "B-SUB_TOTAL.ETC",
21
+ "12": "B-SUB_TOTAL.SERVICE_PRICE",
22
+ "13": "B-SUB_TOTAL.SUBTOTAL_PRICE",
23
+ "14": "B-SUB_TOTAL.TAX_PRICE",
24
+ "15": "B-TOTAL.CASHPRICE",
25
+ "16": "B-TOTAL.CHANGEPRICE",
26
+ "17": "B-TOTAL.CREDITCARDPRICE",
27
+ "18": "B-TOTAL.MENUQTY_CNT",
28
+ "19": "B-TOTAL.TOTAL_PRICE",
29
+ "20": "I-MENU.CNT",
30
+ "21": "I-MENU.DISCOUNTPRICE",
31
+ "22": "I-MENU.NM",
32
+ "23": "I-MENU.NUM",
33
+ "24": "I-MENU.PRICE",
34
+ "25": "I-MENU.SUB.CNT",
35
+ "26": "I-MENU.SUB.NM",
36
+ "27": "I-MENU.SUB.PRICE",
37
+ "28": "I-MENU.UNITPRICE",
38
+ "29": "I-SUB_TOTAL.DISCOUNT_PRICE",
39
+ "30": "I-SUB_TOTAL.ETC",
40
+ "31": "I-SUB_TOTAL.SERVICE_PRICE",
41
+ "32": "I-SUB_TOTAL.SUBTOTAL_PRICE",
42
+ "33": "I-SUB_TOTAL.TAX_PRICE",
43
+ "34": "I-TOTAL.CASHPRICE",
44
+ "35": "I-TOTAL.CHANGEPRICE",
45
+ "36": "I-TOTAL.CREDITCARDPRICE",
46
+ "37": "I-TOTAL.MENUQTY_CNT",
47
+ "38": "I-TOTAL.TOTAL_PRICE"
48
+ }
49
+
50
+ label2id: {
51
+ "B-MENU.CNT": 1,
52
+ "B-MENU.DISCOUNTPRICE": 2,
53
+ "B-MENU.NM": 3,
54
+ "B-MENU.NUM": 4,
55
+ "B-MENU.PRICE": 5,
56
+ "B-MENU.SUB.CNT": 6,
57
+ "B-MENU.SUB.NM": 7,
58
+ "B-MENU.SUB.PRICE": 8,
59
+ "B-MENU.UNITPRICE": 9,
60
+ "B-SUB_TOTAL.DISCOUNT_PRICE": 10,
61
+ "B-SUB_TOTAL.ETC": 11,
62
+ "B-SUB_TOTAL.SERVICE_PRICE": 12,
63
+ "B-SUB_TOTAL.SUBTOTAL_PRICE": 13,
64
+ "B-SUB_TOTAL.TAX_PRICE": 14,
65
+ "B-TOTAL.CASHPRICE": 15,
66
+ "B-TOTAL.CHANGEPRICE": 16,
67
+ "B-TOTAL.CREDITCARDPRICE": 17,
68
+ "B-TOTAL.MENUQTY_CNT": 18,
69
+ "B-TOTAL.TOTAL_PRICE": 19,
70
+ "I-MENU.CNT": 20,
71
+ "I-MENU.DISCOUNTPRICE": 21,
72
+ "I-MENU.NM": 22,
73
+ "I-MENU.NUM": 23,
74
+ "I-MENU.PRICE": 24,
75
+ "I-MENU.SUB.CNT": 25,
76
+ "I-MENU.SUB.NM": 26,
77
+ "I-MENU.SUB.PRICE": 27,
78
+ "I-MENU.UNITPRICE": 28,
79
+ "I-SUB_TOTAL.DISCOUNT_PRICE": 29,
80
+ "I-SUB_TOTAL.ETC": 30,
81
+ "I-SUB_TOTAL.SERVICE_PRICE": 31,
82
+ "I-SUB_TOTAL.SUBTOTAL_PRICE": 32,
83
+ "I-SUB_TOTAL.TAX_PRICE": 33,
84
+ "I-TOTAL.CASHPRICE": 34,
85
+ "I-TOTAL.CHANGEPRICE": 35,
86
+ "I-TOTAL.CREDITCARDPRICE": 36,
87
+ "I-TOTAL.MENUQTY_CNT": 37,
88
+ "I-TOTAL.TOTAL_PRICE": 38,
89
+ "O": 0
90
+ }
91
 
92
  # nielsr/layoutlmv3-finetuned-cord
93
  tokenizer = LayoutLMv3TokenizerFast.from_pretrained("mp-02/layoutlmv3-finetuned-cord", apply_ocr=False)