/tflite_inference.py Secret
Last active
September 25, 2020 13:34
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import tensorflow as tf | |
import numpy as np | |
TFLITE_PATH = "./my_model.tflite" | |
example_input = get_numpy_example() | |
print(f"Using tensorflow {tf.__version__}") # make sure it's the nightly build | |
os.environ["CUDA_VISIBLE_DEVICES"] = "-1" | |
interpreter = tf.compat.v1.lite.Interpreter(model_path=TFLITE_PATH) | |
interpreter.allocate_tensors() | |
input_details = interpreter.get_input_details() | |
output_details = interpreter.get_output_details() | |
interpreter.set_tensor(input_details[0]['index'], example_input) | |
interpreter.invoke() | |
print(interpreter.get_tensor(output_details[0]['index'])) # printing the result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment