mp-02 commited on
Commit
ec3d00d
·
verified ·
1 Parent(s): 05e8dab

Update cord_inference.py

Browse files
Files changed (1) hide show
  1. cord_inference.py +44 -84
cord_inference.py CHANGED
@@ -4,90 +4,50 @@ from transformers import LayoutLMv3TokenizerFast, LayoutLMv3Processor, LayoutLMv
4
  from PIL import Image, ImageDraw, ImageFont
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)
 
4
  from PIL import Image, ImageDraw, ImageFont
5
  from utils import OCR, unnormalize_box
6
 
7
+ labels = [
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
  # nielsr/layoutlmv3-finetuned-cord
53
  tokenizer = LayoutLMv3TokenizerFast.from_pretrained("mp-02/layoutlmv3-finetuned-cord", apply_ocr=False)