[App] Filter low confidence ceil
Browse files
app.py
CHANGED
@@ -25,7 +25,7 @@ st.write(
|
|
25 |
config = Cfg.load_config_from_name('vgg_seq2seq')
|
26 |
config['cnn']['pretrained'] = False
|
27 |
config['device'] = 'cpu'
|
28 |
-
config['predictor']['beamsearch'] =
|
29 |
detector = Predictor(config)
|
30 |
|
31 |
table_detection_model = TableTransformerForObjectDetection.from_pretrained(
|
@@ -43,8 +43,11 @@ def cv_to_PIL(cv_img):
|
|
43 |
return Image.fromarray(cv2.cvtColor(cv_img, cv2.COLOR_BGR2RGB))
|
44 |
|
45 |
|
46 |
-
async def pytess(cell_pil_img):
|
47 |
-
text = detector.predict(cell_pil_img)
|
|
|
|
|
|
|
48 |
return text.strip()
|
49 |
|
50 |
|
@@ -457,9 +460,10 @@ class TableExtractionPipeline():
|
|
457 |
return df
|
458 |
|
459 |
async def start_process(self, image_path: str, TD_THRESHOLD, TSR_THRESHOLD,
|
460 |
-
padd_top, padd_left, padd_bottom,
|
461 |
-
delta_xmin, delta_ymin, delta_xmax,
|
462 |
-
expand_rowcol_bbox_top,
|
|
|
463 |
'''
|
464 |
Initiates process of generating pandas dataframes from raw pdf-page images
|
465 |
|
@@ -516,7 +520,8 @@ class TableExtractionPipeline():
|
|
516 |
# img = self.add_padding(img, 10,10,10,10)
|
517 |
# plt.imshow(img)
|
518 |
# c3.pyplot()
|
519 |
-
sequential_cell_img_list.append(
|
|
|
520 |
|
521 |
cell_ocr_res = await asyncio.gather(*sequential_cell_img_list)
|
522 |
|
@@ -533,9 +538,10 @@ class TableExtractionPipeline():
|
|
533 |
if __name__ == "__main__":
|
534 |
|
535 |
img_name = st.file_uploader("Upload an image with table(s)")
|
536 |
-
st1, st2 = st.columns((1, 1))
|
537 |
TD_th = st1.slider('Table detection threshold', 0.0, 1.0, 0.8)
|
538 |
TSR_th = st2.slider('Table structure recognition threshold', 0.0, 1.0, 0.8)
|
|
|
539 |
|
540 |
st1, st2, st3, st4 = st.columns((1, 1, 1, 1))
|
541 |
|
@@ -551,6 +557,7 @@ if __name__ == "__main__":
|
|
551 |
te.start_process(img_name,
|
552 |
TD_THRESHOLD=TD_th,
|
553 |
TSR_THRESHOLD=TSR_th,
|
|
|
554 |
padd_top=padd_top,
|
555 |
padd_left=padd_left,
|
556 |
padd_bottom=padd_bottom,
|
|
|
25 |
config = Cfg.load_config_from_name('vgg_seq2seq')
|
26 |
config['cnn']['pretrained'] = False
|
27 |
config['device'] = 'cpu'
|
28 |
+
config['predictor']['beamsearch'] = False
|
29 |
detector = Predictor(config)
|
30 |
|
31 |
table_detection_model = TableTransformerForObjectDetection.from_pretrained(
|
|
|
43 |
return Image.fromarray(cv2.cvtColor(cv_img, cv2.COLOR_BGR2RGB))
|
44 |
|
45 |
|
46 |
+
async def pytess(cell_pil_img, threshold: float = 0.5):
|
47 |
+
text, prob = detector.predict(cell_pil_img, return_prob=True)
|
48 |
+
st.write(prob)
|
49 |
+
if prob < threshold:
|
50 |
+
return ""
|
51 |
return text.strip()
|
52 |
|
53 |
|
|
|
460 |
return df
|
461 |
|
462 |
async def start_process(self, image_path: str, TD_THRESHOLD, TSR_THRESHOLD,
|
463 |
+
OCR_THRESHOLD, padd_top, padd_left, padd_bottom,
|
464 |
+
padd_right, delta_xmin, delta_ymin, delta_xmax,
|
465 |
+
delta_ymax, expand_rowcol_bbox_top,
|
466 |
+
expand_rowcol_bbox_bottom):
|
467 |
'''
|
468 |
Initiates process of generating pandas dataframes from raw pdf-page images
|
469 |
|
|
|
520 |
# img = self.add_padding(img, 10,10,10,10)
|
521 |
# plt.imshow(img)
|
522 |
# c3.pyplot()
|
523 |
+
sequential_cell_img_list.append(
|
524 |
+
pytess(cell_pil_img=img, threshold=OCR_THRESHOLD))
|
525 |
|
526 |
cell_ocr_res = await asyncio.gather(*sequential_cell_img_list)
|
527 |
|
|
|
538 |
if __name__ == "__main__":
|
539 |
|
540 |
img_name = st.file_uploader("Upload an image with table(s)")
|
541 |
+
st1, st2, st3 = st.columns((1, 1, 1))
|
542 |
TD_th = st1.slider('Table detection threshold', 0.0, 1.0, 0.8)
|
543 |
TSR_th = st2.slider('Table structure recognition threshold', 0.0, 1.0, 0.8)
|
544 |
+
OCR_th = st3.slider("Text Probs Threshold", 0.0, 1.0, 0.5)
|
545 |
|
546 |
st1, st2, st3, st4 = st.columns((1, 1, 1, 1))
|
547 |
|
|
|
557 |
te.start_process(img_name,
|
558 |
TD_THRESHOLD=TD_th,
|
559 |
TSR_THRESHOLD=TSR_th,
|
560 |
+
OCR_THRESHOLD=OCR_th,
|
561 |
padd_top=padd_top,
|
562 |
padd_left=padd_left,
|
563 |
padd_bottom=padd_bottom,
|