Gabriel commited on
Commit
a36a5bd
1 Parent(s): 7263d32
src/htr_pipeline/pipeline.py CHANGED
@@ -6,7 +6,7 @@ import numpy as np
6
  from src.htr_pipeline.inferencer import Inferencer
7
  from src.htr_pipeline.utils.helper import timer_func
8
  from src.htr_pipeline.utils.parser_xml import XmlParser
9
- from src.htr_pipeline.utils.pipeline_inferencer import PipelineInferencer, XMLHelper
10
  from src.htr_pipeline.utils.preprocess_img import Preprocess
11
  from src.htr_pipeline.utils.process_segmask import SegMaskHelper
12
  from src.htr_pipeline.utils.visualize_xml import XmlViz
 
6
  from src.htr_pipeline.inferencer import Inferencer
7
  from src.htr_pipeline.utils.helper import timer_func
8
  from src.htr_pipeline.utils.parser_xml import XmlParser
9
+ from src.htr_pipeline.utils.pipeline_inferencer import PipelineInferencer
10
  from src.htr_pipeline.utils.preprocess_img import Preprocess
11
  from src.htr_pipeline.utils.process_segmask import SegMaskHelper
12
  from src.htr_pipeline.utils.visualize_xml import XmlViz
src/htr_pipeline/utils/pipeline_inferencer.py CHANGED
@@ -1,3 +1,4 @@
 
1
  from tqdm import tqdm
2
 
3
  from src.htr_pipeline.utils.process_segmask import SegMaskHelper
@@ -17,7 +18,6 @@ class PipelineInferencer:
17
  image, inferencer, pred_score_threshold_regions, pred_score_threshold_lines, containments_threshold
18
  )
19
 
20
- print(template_data)
21
  return self.xml_helper.render(template_data)
22
 
23
  def _process_regions(
@@ -35,7 +35,7 @@ class PipelineInferencer:
35
  containments_threshold=containments_threshold,
36
  visualize=False,
37
  )
38
-
39
  region_data_list = []
40
  for i, data in tqdm(enumerate(zip(regions_cropped_ordered, reg_polygons_ordered, reg_masks_ordered))):
41
  region_data = self._create_region_data(
@@ -84,6 +84,12 @@ class PipelineInferencer:
84
 
85
  text_lines = []
86
  htr_scores = []
 
 
 
 
 
 
87
  for index, (line, line_pol) in enumerate(zip(lines_cropped_ordered, line_polygons_ordered_trans)):
88
  line_data, htr_score = self._create_line_data(line, line_pol, index, region_id, inferencer, htr_threshold)
89
 
@@ -91,6 +97,11 @@ class PipelineInferencer:
91
  text_lines.append(line_data)
92
  htr_scores.append(htr_score)
93
 
 
 
 
 
 
94
  return text_lines, htr_scores
95
 
96
  def _create_line_data(self, line, line_pol, index, region_id, inferencer, htr_threshold):
 
1
+ import gradio as gr
2
  from tqdm import tqdm
3
 
4
  from src.htr_pipeline.utils.process_segmask import SegMaskHelper
 
18
  image, inferencer, pred_score_threshold_regions, pred_score_threshold_lines, containments_threshold
19
  )
20
 
 
21
  return self.xml_helper.render(template_data)
22
 
23
  def _process_regions(
 
35
  containments_threshold=containments_threshold,
36
  visualize=False,
37
  )
38
+ gr.Info(f"Found {len(regions_cropped_ordered)} Regions to parse")
39
  region_data_list = []
40
  for i, data in tqdm(enumerate(zip(regions_cropped_ordered, reg_polygons_ordered, reg_masks_ordered))):
41
  region_data = self._create_region_data(
 
84
 
85
  text_lines = []
86
  htr_scores = []
87
+
88
+ id_number = region_id.split("_")[1]
89
+ total_lines_len = len(lines_cropped_ordered)
90
+
91
+ gr.Info(f" Region {id_number}, found {total_lines_len} lines to parse and transcribe.")
92
+
93
  for index, (line, line_pol) in enumerate(zip(lines_cropped_ordered, line_polygons_ordered_trans)):
94
  line_data, htr_score = self._create_line_data(line, line_pol, index, region_id, inferencer, htr_threshold)
95
 
 
97
  text_lines.append(line_data)
98
  htr_scores.append(htr_score)
99
 
100
+ remaining_lines = total_lines_len - index - 1
101
+
102
+ if (index + 1) % 10 == 0 and remaining_lines > 5: # +1 because index starts at 0
103
+ gr.Info(f"Parsed {index + 1} lines. Still {remaining_lines} lines left to transcribe.")
104
+
105
  return text_lines, htr_scores
106
 
107
  def _create_line_data(self, line, line_pol, index, region_id, inferencer, htr_threshold):
src/htr_pipeline/utils/visualize_xml.py CHANGED
@@ -1,6 +1,7 @@
1
  import random
2
  import xml.etree.ElementTree as ET
3
 
 
4
  from PIL import Image, ImageDraw, ImageFont
5
 
6
 
@@ -24,7 +25,7 @@ class XmlViz:
24
  font_path = font_path_tff
25
 
26
  max_bbox_width = 0 # Initialize maximum bounding box width
27
-
28
  for textregion in self.root.findall(f".//{self.namespace}TextRegion"):
29
  coords = textregion.find(f"{self.namespace}Coords").attrib["points"].split()
30
  points = [tuple(map(int, point.split(","))) for point in coords]
 
1
  import random
2
  import xml.etree.ElementTree as ET
3
 
4
+ import gradio as gr
5
  from PIL import Image, ImageDraw, ImageFont
6
 
7
 
 
25
  font_path = font_path_tff
26
 
27
  max_bbox_width = 0 # Initialize maximum bounding box width
28
+ gr.Info("Parsing XML to visualize the data.")
29
  for textregion in self.root.findall(f".//{self.namespace}TextRegion"):
30
  coords = textregion.find(f"{self.namespace}Coords").attrib["points"].split()
31
  points = [tuple(map(int, point.split(","))) for point in coords]