diff options
author | Dmitrii Agibov <dmitrii.agibov@arm.com> | 2022-09-08 14:24:39 +0100 |
---|---|---|
committer | Dmitrii Agibov <dmitrii.agibov@arm.com> | 2022-09-09 17:21:48 +0100 |
commit | f5b293d0927506c2a979a091bf0d07ecc78fa181 (patch) | |
tree | 4de585b7cb6ed34da8237063752270189a730a41 /src/mlia/nn/tensorflow/utils.py | |
parent | cde0c6ee140bd108849bff40467d8f18ffc332ef (diff) | |
download | mlia-f5b293d0927506c2a979a091bf0d07ecc78fa181.tar.gz |
MLIA-386 Simplify typing in the source code
- Enable deferred annotations evaluation
- Use builtin types for type hints whenever possible
- Use | syntax for union types
- Rename mlia.core._typing into mlia.core.typing
Change-Id: I3f6ffc02fa069c589bdd9e8bddbccd504285427a
Diffstat (limited to 'src/mlia/nn/tensorflow/utils.py')
-rw-r--r-- | src/mlia/nn/tensorflow/utils.py | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/src/mlia/nn/tensorflow/utils.py b/src/mlia/nn/tensorflow/utils.py index b1034d9..6250f56 100644 --- a/src/mlia/nn/tensorflow/utils.py +++ b/src/mlia/nn/tensorflow/utils.py @@ -2,11 +2,12 @@ # SPDX-FileCopyrightText: Copyright The TensorFlow Authors. All Rights Reserved. # SPDX-License-Identifier: Apache-2.0 """Collection of useful functions for optimizations.""" +from __future__ import annotations + import logging from pathlib import Path from typing import Callable from typing import Iterable -from typing import Union import numpy as np import tensorflow as tf @@ -101,21 +102,19 @@ def convert_tf_to_tflite(model: str, quantized: bool = False) -> Interpreter: return tflite_model -def save_keras_model(model: tf.keras.Model, save_path: Union[str, Path]) -> None: +def save_keras_model(model: tf.keras.Model, save_path: str | Path) -> None: """Save Keras model at provided path.""" # Checkpoint: saving the optimizer is necessary. model.save(save_path, include_optimizer=True) -def save_tflite_model( - model: tf.lite.TFLiteConverter, save_path: Union[str, Path] -) -> None: +def save_tflite_model(model: tf.lite.TFLiteConverter, save_path: str | Path) -> None: """Save TFLite model at provided path.""" with open(save_path, "wb") as file: file.write(model) -def is_tflite_model(model: Union[Path, str]) -> bool: +def is_tflite_model(model: str | Path) -> bool: """Check if model type is supported by TFLite API. TFLite model is indicated by the model file extension .tflite @@ -124,7 +123,7 @@ def is_tflite_model(model: Union[Path, str]) -> bool: return model_path.suffix == ".tflite" -def is_keras_model(model: Union[Path, str]) -> bool: +def is_keras_model(model: str | Path) -> bool: """Check if model type is supported by Keras API. Keras model is indicated by: @@ -139,7 +138,7 @@ def is_keras_model(model: Union[Path, str]) -> bool: return model_path.suffix in (".h5", ".hdf5") -def is_tf_model(model: Union[Path, str]) -> bool: +def is_tf_model(model: str | Path) -> bool: """Check if model type is supported by TensorFlow API. TensorFlow model is indicated if its directory (meaning saved model) |