From f0d6be8d881c0eb494b396cd3abb0e085eb2e8dd Mon Sep 17 00:00:00 2001 From: felix Date: Wed, 24 Apr 2024 10:27:00 +0200 Subject: [PATCH] test --- doctr/file_utils.py | 5 +++++ references/classification/latency_tensorflow.py | 8 ++++++-- references/classification/train_tensorflow_character.py | 4 ++++ references/classification/train_tensorflow_orientation.py | 4 ++++ references/detection/evaluate_tensorflow.py | 4 ++++ references/detection/latency_tensorflow.py | 7 ++++++- references/detection/train_tensorflow.py | 4 ++++ references/recognition/evaluate_tensorflow.py | 4 ++++ references/recognition/latency_tensorflow.py | 8 ++++++-- references/recognition/train_tensorflow.py | 4 ++++ 10 files changed, 47 insertions(+), 5 deletions(-) diff --git a/doctr/file_utils.py b/doctr/file_utils.py index 7f35b34ae8..b2b6174a70 100644 --- a/doctr/file_utils.py +++ b/doctr/file_utils.py @@ -85,6 +85,11 @@ ) +def ensure_keras_v2() -> None: # pragma: no cover + if not os.environ.get("TF_USE_LEGACY_KERAS") == "1": + os.environ["TF_USE_LEGACY_KERAS"] = "1" + + def requires_package(name: str, extra_message: Optional[str] = None) -> None: # pragma: no cover """ package requirement helper diff --git a/references/classification/latency_tensorflow.py b/references/classification/latency_tensorflow.py index 639b60e3a5..5a1d3f7845 100644 --- a/references/classification/latency_tensorflow.py +++ b/references/classification/latency_tensorflow.py @@ -9,14 +9,18 @@ import os import time +from doctr.file_utils import ensure_keras_v2 + +ensure_keras_v2() + os.environ["USE_TF"] = "1" os.environ["TF_CPP_MIN_LOG_LEVEL"] = "2" -from doctr.models import classification # isort: skip - import numpy as np import tensorflow as tf +from doctr.models import classification + def main(args): if args.gpu: diff --git a/references/classification/train_tensorflow_character.py b/references/classification/train_tensorflow_character.py index 10c479bdc6..3e366de661 100644 --- a/references/classification/train_tensorflow_character.py +++ b/references/classification/train_tensorflow_character.py @@ -5,6 +5,10 @@ import os +from doctr.file_utils import ensure_keras_v2 + +ensure_keras_v2() + os.environ["USE_TF"] = "1" os.environ["TF_CPP_MIN_LOG_LEVEL"] = "2" diff --git a/references/classification/train_tensorflow_orientation.py b/references/classification/train_tensorflow_orientation.py index 314ed4bbb7..a1f1e7e691 100644 --- a/references/classification/train_tensorflow_orientation.py +++ b/references/classification/train_tensorflow_orientation.py @@ -5,6 +5,10 @@ import os +from doctr.file_utils import ensure_keras_v2 + +ensure_keras_v2() + os.environ["USE_TF"] = "1" os.environ["TF_CPP_MIN_LOG_LEVEL"] = "2" diff --git a/references/detection/evaluate_tensorflow.py b/references/detection/evaluate_tensorflow.py index 139932f2c4..ea77037804 100644 --- a/references/detection/evaluate_tensorflow.py +++ b/references/detection/evaluate_tensorflow.py @@ -5,6 +5,10 @@ import os +from doctr.file_utils import ensure_keras_v2 + +ensure_keras_v2() + from doctr.file_utils import CLASS_NAME os.environ["USE_TF"] = "1" diff --git a/references/detection/latency_tensorflow.py b/references/detection/latency_tensorflow.py index ba2c8e7c1c..b2d973fa6f 100644 --- a/references/detection/latency_tensorflow.py +++ b/references/detection/latency_tensorflow.py @@ -9,14 +9,19 @@ import os import time +from doctr.file_utils import ensure_keras_v2 + +ensure_keras_v2() + os.environ["USE_TF"] = "1" os.environ["TF_CPP_MIN_LOG_LEVEL"] = "2" -from doctr.models import detection # isort: skip import numpy as np import tensorflow as tf +from doctr.models import detection + def main(args): if args.gpu: diff --git a/references/detection/train_tensorflow.py b/references/detection/train_tensorflow.py index d8b4b9c708..ebdf707021 100644 --- a/references/detection/train_tensorflow.py +++ b/references/detection/train_tensorflow.py @@ -5,6 +5,10 @@ import os +from doctr.file_utils import ensure_keras_v2 + +ensure_keras_v2() + os.environ["USE_TF"] = "1" os.environ["TF_CPP_MIN_LOG_LEVEL"] = "2" diff --git a/references/recognition/evaluate_tensorflow.py b/references/recognition/evaluate_tensorflow.py index 62651245c4..4e00715513 100644 --- a/references/recognition/evaluate_tensorflow.py +++ b/references/recognition/evaluate_tensorflow.py @@ -5,6 +5,10 @@ import os +from doctr.file_utils import ensure_keras_v2 + +ensure_keras_v2() + os.environ["USE_TF"] = "1" os.environ["TF_CPP_MIN_LOG_LEVEL"] = "2" diff --git a/references/recognition/latency_tensorflow.py b/references/recognition/latency_tensorflow.py index fc30cc051e..dfae409473 100644 --- a/references/recognition/latency_tensorflow.py +++ b/references/recognition/latency_tensorflow.py @@ -9,14 +9,18 @@ import os import time +from doctr.file_utils import ensure_keras_v2 + +ensure_keras_v2() + os.environ["USE_TF"] = "1" os.environ["TF_CPP_MIN_LOG_LEVEL"] = "2" -from doctr.models import recognition # isort: skip - import numpy as np import tensorflow as tf +from doctr.models import recognition + def main(args): if args.gpu: diff --git a/references/recognition/train_tensorflow.py b/references/recognition/train_tensorflow.py index ac839bc2de..3e49e0ffe5 100644 --- a/references/recognition/train_tensorflow.py +++ b/references/recognition/train_tensorflow.py @@ -5,6 +5,10 @@ import os +from doctr.file_utils import ensure_keras_v2 + +ensure_keras_v2() + os.environ["USE_TF"] = "1" os.environ["TF_CPP_MIN_LOG_LEVEL"] = "2"