mirror of
https://github.com/qurator-spk/eynollah.git
synced 2026-05-26 07:39:22 +02:00
drop unnecessary TF / Torch imports
This commit is contained in:
parent
bdfebd2c70
commit
3de1407d18
7 changed files with 6 additions and 36 deletions
|
|
@ -1,7 +1,3 @@
|
|||
# NOTE: For predictable order of imports of torch/shapely/tensorflow
|
||||
# this must be the first import of the CLI!
|
||||
from ..eynollah_imports import imported_libs
|
||||
|
||||
from .cli import main
|
||||
from .cli_binarize import binarize_cli
|
||||
from .cli_enhance import enhance_cli
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ import os
|
|||
import time
|
||||
from typing import Optional
|
||||
from pathlib import Path
|
||||
import tensorflow as tf
|
||||
import numpy as np
|
||||
import cv2
|
||||
|
||||
|
|
@ -64,12 +63,6 @@ class EynollahImageExtractor(Eynollah):
|
|||
|
||||
t_start = time.time()
|
||||
|
||||
try:
|
||||
for device in tf.config.list_physical_devices('GPU'):
|
||||
tf.config.experimental.set_memory_growth(device, True)
|
||||
except:
|
||||
self.logger.warning("no GPU device available")
|
||||
|
||||
self.logger.info("Loading models...")
|
||||
self.setup_models()
|
||||
self.logger.info(f"Model initialization complete ({time.time() - t_start:.1f}s)")
|
||||
|
|
|
|||
|
|
@ -1,13 +0,0 @@
|
|||
"""
|
||||
Load libraries with possible race conditions once. This must be imported as the first module of eynollah.
|
||||
"""
|
||||
import os
|
||||
os.environ['TF_USE_LEGACY_KERAS'] = '1' # avoid Keras 3 after TF 2.15
|
||||
|
||||
from ocrd_utils import tf_disable_interactive_logs
|
||||
from torch import *
|
||||
tf_disable_interactive_logs()
|
||||
import tensorflow.keras
|
||||
from shapely import *
|
||||
imported_libs = True
|
||||
__all__ = ['imported_libs']
|
||||
|
|
@ -14,10 +14,6 @@ from cv2.typing import MatLike
|
|||
from xml.etree import ElementTree as ET
|
||||
from PIL import Image, ImageDraw
|
||||
import numpy as np
|
||||
try:
|
||||
import torch
|
||||
except ImportError:
|
||||
torch = None
|
||||
|
||||
|
||||
from .eynollah import Eynollah
|
||||
|
|
|
|||
|
|
@ -17,10 +17,6 @@ import cv2
|
|||
import numpy as np
|
||||
import statistics
|
||||
|
||||
os.environ['TF_USE_LEGACY_KERAS'] = '1' # avoid Keras 3 after TF 2.15
|
||||
import tensorflow as tf
|
||||
from tensorflow.keras.models import Model
|
||||
|
||||
from .eynollah import Eynollah
|
||||
from .model_zoo import EynollahModelZoo
|
||||
from .utils.resize import resize_image
|
||||
|
|
|
|||
|
|
@ -269,6 +269,10 @@ class EynollahModelZoo:
|
|||
"""
|
||||
Load decoder for OCR
|
||||
"""
|
||||
os.environ['TF_USE_LEGACY_KERAS'] = '1' # avoid Keras 3 after TF 2.15
|
||||
from ocrd_utils import tf_disable_interactive_logs
|
||||
tf_disable_interactive_logs()
|
||||
|
||||
from tensorflow.keras.layers import StringLookup
|
||||
|
||||
characters = self._load_characters()
|
||||
|
|
|
|||
|
|
@ -1,10 +1,8 @@
|
|||
# NOTE: For predictable order of imports of torch/shapely/tensorflow
|
||||
# this must be the first import of the CLI!
|
||||
from .eynollah_imports import imported_libs
|
||||
from .processor import EynollahProcessor
|
||||
from click import command
|
||||
from ocrd.decorators import ocrd_cli_options, ocrd_cli_wrap_processor
|
||||
|
||||
from .processor import EynollahProcessor
|
||||
|
||||
@command()
|
||||
@ocrd_cli_options
|
||||
def main(*args, **kwargs):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue