utils_ocr: avoid module-level import of TF

This commit is contained in:
Robert Sachunsky 2026-05-21 22:50:53 +02:00
parent f3a93983c0
commit 0836230c6b
2 changed files with 9 additions and 3 deletions

View file

@ -4,7 +4,9 @@ from itertools import islice
import numpy as np
import cv2
import tensorflow as tf
# avoid module-level import:
# import tensorflow as tf
# (wait for tf-keras and logging setup in ModelZoo.load_model)
from scipy.signal import find_peaks
from scipy.ndimage import gaussian_filter1d
from PIL import Image, ImageDraw, ImageFont
@ -13,6 +15,8 @@ from .resize import resize_image
def decode_batch_predictions(pred, num_to_char, max_len = 128):
import tensorflow as tf
# input_len is the product of the batch size and the
# number of time steps.
input_len = np.ones(pred.shape[0]) * pred.shape[1]
@ -40,6 +44,8 @@ def decode_batch_predictions(pred, num_to_char, max_len = 128):
def distortion_free_resize(image, img_size):
import tensorflow as tf
w, h = img_size
image = tf.image.resize(image, size=(h, w), preserve_aspect_ratio=True)

View file

@ -30,7 +30,7 @@ def test_run_eynollah_ocr_filename(
'-o', str(outfile.parent),
] + options,
[
# FIXME: ocr has no logging!
'output filename:'
]
)
assert outfile.exists()
@ -57,7 +57,7 @@ def test_run_eynollah_ocr_directory(
'-o', str(outdir),
],
[
# FIXME: ocr has no logging!
'output filename:'
]
)
assert len(list(outdir.iterdir())) == 2