2525
2626
2727class NemotronOcrPrediction (TypedDict ):
28- """Exact prediction schema returned by `nemotron_ocr` 1.0.1 ."""
28+ """Exact prediction schema returned by `nemotron_ocr`."""
2929
3030 text : str
3131 confidence : float
@@ -119,7 +119,7 @@ def _prediction_to_cell(
119119 image_height : int ,
120120 scale : int ,
121121 ) -> TextCell :
122- # `nemotron_ocr` 1.0.1 returns normalized `left/right` and an inverted
122+ # `nemotron_ocr` returns normalized `left/right` and an inverted
123123 # pair `lower/upper`, where `lower` is the top Y and `upper` is the
124124 # bottom Y in image coordinates.
125125 left = (prediction ["left" ] * image_width ) / scale + ocr_rect .l
@@ -160,8 +160,14 @@ def __call__(
160160 with TimeRecorder (conv_res , "ocr" ):
161161 ocr_rects = self .get_ocr_rects (page )
162162
163+ print (
164+ "[nemotron-debug] "
165+ f"page={ page .page_no } rect_count={ len (ocr_rects )} "
166+ f"rects={ [rect .as_tuple () for rect in ocr_rects ]} "
167+ )
168+
163169 all_ocr_cells = []
164- for ocr_rect in ocr_rects :
170+ for crop_index , ocr_rect in enumerate ( ocr_rects ) :
165171 if ocr_rect .area () == 0 :
166172 continue
167173
@@ -171,15 +177,37 @@ def __call__(
171177 image_width , image_height = high_res_image .size
172178 image_array = numpy .array (high_res_image )
173179
174- raw_predictions = cast (
175- Sequence [NemotronOcrPrediction ],
176- self .reader (
177- image_array ,
178- merge_level = self .options .merge_level ,
179- visualize = False ,
180- ),
180+ print (
181+ "[nemotron-debug] "
182+ f"page={ page .page_no } crop={ crop_index } "
183+ f"rect={ ocr_rect .as_tuple ()} "
184+ f"size={ image_width } x{ image_height } "
185+ f"shape={ image_array .shape } "
186+ f"dtype={ image_array .dtype } "
187+ f"contiguous={ image_array .flags .c_contiguous } "
181188 )
182189
190+ try :
191+ raw_predictions = cast (
192+ Sequence [NemotronOcrPrediction ],
193+ self .reader (
194+ image_array ,
195+ merge_level = self .options .merge_level ,
196+ visualize = False ,
197+ ),
198+ )
199+ except Exception :
200+ print (
201+ "[nemotron-debug] "
202+ f"FAILED page={ page .page_no } crop={ crop_index } "
203+ f"rect={ ocr_rect .as_tuple ()} "
204+ f"size={ image_width } x{ image_height } "
205+ f"shape={ image_array .shape } "
206+ f"dtype={ image_array .dtype } "
207+ f"contiguous={ image_array .flags .c_contiguous } "
208+ )
209+ raise
210+
183211 del high_res_image
184212 del image_array
185213
0 commit comments