Skip to content

Commit bcaf3df

Browse files
author
marwan37
committed
cleanup utils
1 parent bbbd82c commit bcaf3df

File tree

3 files changed

+10
-13
lines changed

3 files changed

+10
-13
lines changed

omni-reader/utils/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
create_model_comparison_card,
3131
create_model_similarity_matrix,
3232
create_summary_visualization,
33+
create_ocr_batch_visualization
3334
)
3435
from .ocr_processing import (
3536
log_image_metadata,

omni-reader/utils/metrics.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -193,21 +193,16 @@ def compare_multi_model(
193193
Returns:
194194
Dict[str, Dict[str, Union[float, int, Dict]]]: A dictionary of model names to metrics.
195195
"""
196-
# Initialize results dictionary
197196
results = {}
198197

199-
# Calculate metrics for each model
200198
for model_display, text in model_texts.items():
201199
model_metrics = {}
202200

203-
# Basic metrics
204201
model_metrics["CER"] = cer(ground_truth, text)
205202
model_metrics["WER"] = wer(ground_truth, text)
206203

207-
# Detailed error analysis
208204
model_analysis = analyze_errors(ground_truth, text)
209205

210-
# Add detailed metrics
211206
model_metrics.update(
212207
{
213208
"Insertions": model_analysis.insertions,
@@ -221,7 +216,6 @@ def compare_multi_model(
221216
}
222217
)
223218

224-
# Store in results
225219
results[model_display] = model_metrics
226220

227221
return results
@@ -258,7 +252,7 @@ def calculate_model_similarities(
258252
similarity_counts = {}
259253

260254
for result in results:
261-
# Build a mapping from model display names to their corresponding text.
255+
# Map model display names to their corresponding text
262256
model_texts = {}
263257
for display in model_displays:
264258
key = f"raw_text_{display.lower().replace(' ', '_')}"
@@ -268,11 +262,11 @@ def calculate_model_similarities(
268262
if text:
269263
model_texts[display] = text
270264

271-
# Only proceed if at least two models have valid text.
265+
# Only proceed if at least two models have valid text
272266
if len(model_texts) < 2:
273267
continue
274268

275-
# Compute pairwise similarity for each combination.
269+
# Compute pairwise similarity for each combination
276270
for i in range(len(model_displays)):
277271
for j in range(i + 1, len(model_displays)):
278272
model1 = model_displays[i]
@@ -286,7 +280,7 @@ def calculate_model_similarities(
286280
similarity_sums[pair_key] = similarity_sums.get(pair_key, 0) + similarity
287281
similarity_counts[pair_key] = similarity_counts.get(pair_key, 0) + 1
288282

289-
# Average the similarities for each pair.
283+
# Average the similarities for each pair
290284
similarities = {
291285
pair: similarity_sums[pair] / similarity_counts[pair] for pair in similarity_sums
292286
}

omni-reader/utils/ocr_processing.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -345,19 +345,21 @@ def process_result_and_track_metrics(
345345

346346
confidence_scores.append(confidence)
347347

348+
text_length = len(formatted_result["raw_text"])
349+
348350
if track_metadata:
349351
log_image_metadata(
350352
prefix=prefix,
351353
index=index,
352354
image_name=image_name,
353355
processing_time=processing_time,
354-
text_length=len(formatted_result["raw_text"]),
356+
text_length=text_length,
355357
confidence=confidence,
356358
)
357359

358360
logger.info(
359361
f"{display} OCR [{index + 1}/{len(images)}]: {image_name} - "
360-
f"{len(formatted_result['raw_text'])} chars, "
362+
f"{text_length} chars, "
361363
f"confidence: {confidence:.2f}, "
362364
f"{processing_time:.2f} seconds"
363365
)
@@ -517,7 +519,7 @@ def run_ocr(
517519
) -> Union[Dict[str, Any], pl.DataFrame, Dict[str, pl.DataFrame]]:
518520
"""Unified interface for running OCR on images with different modes.
519521
520-
This function intelligently handles different combinations of inputs:
522+
This function handles different combinations of inputs:
521523
- Single image + single model
522524
- Single image + multiple models
523525
- Multiple images + single model

0 commit comments

Comments
 (0)