mirror of
https://github.com/qurator-spk/eynollah.git
synced 2026-05-26 07:39:22 +02:00
utils_ocr: avoid module-level import of TF
This commit is contained in:
parent
f3a93983c0
commit
0836230c6b
2 changed files with 9 additions and 3 deletions
|
|
@ -4,7 +4,9 @@ from itertools import islice
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import cv2
|
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.signal import find_peaks
|
||||||
from scipy.ndimage import gaussian_filter1d
|
from scipy.ndimage import gaussian_filter1d
|
||||||
from PIL import Image, ImageDraw, ImageFont
|
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):
|
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
|
# input_len is the product of the batch size and the
|
||||||
# number of time steps.
|
# number of time steps.
|
||||||
input_len = np.ones(pred.shape[0]) * pred.shape[1]
|
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):
|
def distortion_free_resize(image, img_size):
|
||||||
|
import tensorflow as tf
|
||||||
|
|
||||||
w, h = img_size
|
w, h = img_size
|
||||||
image = tf.image.resize(image, size=(h, w), preserve_aspect_ratio=True)
|
image = tf.image.resize(image, size=(h, w), preserve_aspect_ratio=True)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ def test_run_eynollah_ocr_filename(
|
||||||
'-o', str(outfile.parent),
|
'-o', str(outfile.parent),
|
||||||
] + options,
|
] + options,
|
||||||
[
|
[
|
||||||
# FIXME: ocr has no logging!
|
'output filename:'
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
assert outfile.exists()
|
assert outfile.exists()
|
||||||
|
|
@ -57,7 +57,7 @@ def test_run_eynollah_ocr_directory(
|
||||||
'-o', str(outdir),
|
'-o', str(outdir),
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
# FIXME: ocr has no logging!
|
'output filename:'
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
assert len(list(outdir.iterdir())) == 2
|
assert len(list(outdir.iterdir())) == 2
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue