Last active
May 9, 2024 04:12
-
-
Save jobayer/273455598db26da56a19a42f4419a6c3 to your computer and use it in GitHub Desktop.
Predict audio files using TFLite model in Raspberry PI (Tested on RPI 3B+)
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
mdl_path = "models/bently.tflite" | |
audio_files_dir = "audio" | |
interpreter = tflite.Interpreter(model_path=mdl_path) | |
interpreter.allocate_tensors() | |
input_details = interpreter.get_input_details() | |
output_details = interpreter.get_output_details() | |
print("Input details:", input_details) | |
print("Output details:", output_details) | |
audio_files = get_audio_files(audio_files_dir) | |
for file in audio_files: | |
data = prepare_data(file) | |
data = data.astype(np.float32) | |
data = np.expand_dims(data, axis=0) | |
interpreter.set_tensor(input_details[0]['index'], data) | |
interpreter.invoke() | |
output_data = interpreter.get_tensor(output_details[0]['index']) | |
print(f"File: {file}, Output: {output_data}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment