more explicit tensorflow checks

This commit is contained in:
Mike 2024-11-17 17:14:29 -06:00
parent 99cd87e889
commit 172e25bfa2
No known key found for this signature in database
GPG key ID: 874DB5A2BE859A11
2 changed files with 8 additions and 5 deletions

View file

@ -119,15 +119,16 @@ class Model():
return tflite_interpreter.get_tensor(output_index)[None, ]
except ImportError:
try:
from importlib.util import find_spec
if find_spec("tensorflow") is not None and find_spec("tflite_runtime") is None:
logging.warning("Tried to import the tflite runtime, but it was not found. Using tensorflow instead.")
from tensorflow.lite.python import interpreter as tflite
def tflite_predict(tflite_interpreter, input_index, output_index, x):
tflite_interpreter.set_tensor(input_index, x)
tflite_interpreter.invoke()
return tflite_interpreter.get_tensor(output_index)[None, ]
except ImportError:
else:
logging.warning("Tried to import the tflite runtime, but it was not found. "
"Trying to switching to onnxruntime instead, if appropriate models are available.")
if wakeword_models != [] and all(['.onnx' in i for i in wakeword_models]):

View file

@ -96,9 +96,11 @@ class AudioFeatures():
try:
import tflite_runtime.interpreter as tflite
except ImportError:
try:
from importlib.util import find_spec
if find_spec("tensorflow") is not None and find_spec("tflite_runtime") is None:
logging.warning("Tried to import the tflite runtime, but it was not found. Using tensorflow instead.")
from tensorflow.lite.python import interpreter as tflite
except ImportError:
else:
raise ValueError("Tried to import the TFLite runtime, but it was not found."
"Neither was the TensorFlow interpreter."
"Please install TFLite runtime using `pip install tflite-runtime`")