Skip to content

Instantly share code, notes, and snippets.

@farmaker47
Created December 10, 2020 04:20
Show Gist options
  • Save farmaker47/4eec4c994caefe52e2f056b54822c03b to your computer and use it in GitHub Desktop.
Save farmaker47/4eec4c994caefe52e2f056b54822c03b to your computer and use it in GitHub Desktop.
interpreter = tf.lite.Interpreter('/path/to/yamnet.tflite')
input_details = interpreter.get_input_details()
waveform_input_index = input_details[0]['index']
output_details = interpreter.get_output_details()
scores_output_index = output_details[0]['index']
embeddings_output_index = output_details[1]['index']
spectrogram_output_index = output_details[2]['index']
# Input: 3 seconds of silence as mono 16 kHz waveform samples.
waveform = np.zeros(3 * 16000, dtype=np.float32)
interpreter.resize_tensor_input(waveform_input_index, [len(waveform)], strict=True)
interpreter.allocate_tensors()
interpreter.set_tensor(waveform_input_index, waveform)
interpreter.invoke()
scores, embeddings, spectrogram = (
interpreter.get_tensor(scores_output_index),
interpreter.get_tensor(embeddings_output_index),
interpreter.get_tensor(spectrogram_output_index))
print(scores.shape, embeddings.shape, spectrogram.shape) # (N, 521) (N, 1024) (M, 64)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment