fasdfsa commited on
Commit
883f518
·
1 Parent(s): 2c67080

add main.py

Browse files
Files changed (3) hide show
  1. main.py +46 -0
  2. readme.txt +31 -1
  3. scripts/try_pix2text_mfr.py +2 -1
main.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ from pix2text import Pix2Text, merge_line_texts
3
+
4
+ img_fp = './examples/en1.jpg'
5
+ p2t = Pix2Text.from_config()
6
+ outs = p2t.recognize_text_formula(img_fp, resized_shape=768, return_text=True)
7
+ print(outs)
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+ # #! pip install pix2text>=1.1
19
+ # import requests
20
+ # from io import BytesIO
21
+ # from PIL import Image
22
+
23
+ # from pix2text import Pix2Text, merge_line_texts
24
+
25
+ # def download_img(url):
26
+ # response = requests.get(url)
27
+ # image_file = BytesIO(response.content)
28
+ # return Image.open(image_file).convert('RGB')
29
+
30
+ # image_fps = [
31
+ # 'https://raw.githubusercontent.com/breezedeus/Pix2Text/main/docs/examples/formula.jpg',
32
+ # 'https://raw.githubusercontent.com/breezedeus/Pix2Text/main/docs/examples/math-formula-42.png',
33
+ # ]
34
+ # images = [download_img(img_fp) for img_fp in image_fps]
35
+
36
+ # p2t = Pix2Text.from_config()
37
+ # outs = p2t.recognize_formula(images, return_text=True) # recognize pure formula images
38
+ # print('outs for pure formula images', outs)
39
+
40
+ # mixed_img_fp = 'https://raw.githubusercontent.com/breezedeus/Pix2Text/main/docs/examples/en1.jpg'
41
+ # mixed_img = download_img(mixed_img_fp)
42
+
43
+ # outs2 = p2t.recognize(mixed_img, file_type='text_formula', return_text=True, save_analysis_res='en1-out.jpg') # recognize mixed images
44
+ # print(outs2)
45
+ # from IPython.display import display
46
+ # display(Image.open('en1-out.jpg'))
readme.txt CHANGED
@@ -1 +1,31 @@
1
- https://github.com/breezedeus/Pix2Text
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ https://github.com/breezedeus/Pix2Text
3
+
4
+ pip install pix2text
5
+ # base 环境
6
+
7
+ p2t predict -l en,ch_sim --resized-shape 768 --file-type text_formula -i docs/examples/en1.jpg --save-debug-res out-debug-en1.jpg
8
+ # 成功识别
9
+
10
+ p2t predict -l en,ch_sim --mfd-config '{"model_name": "mfd-pro-1.5", "model_backend": "onnx"}' --formula-ocr-config '{"model_name":"mfr-pro-1.5","model_backend":"onnx"}' --text-ocr-config '{"rec_model_name": "doc-densenet_lite_666-gru_large"}' --resized-shape 768 --file-type text_formula -i docs/examples/en1.jpg --save-debug-res out-debug-en1.jpg
11
+ # 付费模型
12
+
13
+ C:\Users\Administrator\AppData\Roaming\pix2text\1.1\table-rec\model.safetensors
14
+ # 模型保存在这了
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+ conda create formulaocr python==3.10 pip
28
+
29
+ pip install -r .\requirements.txt
30
+
31
+
scripts/try_pix2text_mfr.py CHANGED
@@ -63,7 +63,7 @@ def test_tokenizer_consistency(processor, test_strings=None):
63
  print("="*50 + "\n")
64
 
65
  model = 'breezedeus/pix2text-mfr'
66
- model = 'models/checkpoint-683356'
67
  processor = TrOCRProcessor.from_pretrained(model)
68
 
69
  # 测试Tokenizer的编码和解码是否一致
@@ -71,6 +71,7 @@ processor = TrOCRProcessor.from_pretrained(model)
71
 
72
  # model = ORTModelForVision2Seq.from_pretrained(model, use_cache=False)
73
 
 
74
  model = VisionEncoderDecoderModel.from_pretrained(model)
75
 
76
  image_fps = [
 
63
  print("="*50 + "\n")
64
 
65
  model = 'breezedeus/pix2text-mfr'
66
+
67
  processor = TrOCRProcessor.from_pretrained(model)
68
 
69
  # 测试Tokenizer的编码和解码是否一致
 
71
 
72
  # model = ORTModelForVision2Seq.from_pretrained(model, use_cache=False)
73
 
74
+ model = 'models/checkpoint-683356'
75
  model = VisionEncoderDecoderModel.from_pretrained(model)
76
 
77
  image_fps = [