1.I downloaded the Classifier model TensorFlow Lite (float32) from dashboard.
2.Gen raw features:
wav_data, sr = librosa.load(wav_file)
if length is None:
length = len(wav_data) - offset
out_ptr = wav_data
rounded_audio_array = out_ptr.flatten()
rounded_audio_array = rounded_audio_array[offset:offset + length]
# rounded_audio_array = [(float(value))
rounded_audio_array = [format(value, '.2f')
for value in rounded_audio_array]
samples = np.array(samples, dtype=np.float32)
3.Gen processed features:
axes = [‘a’] # Axes names, can only be one for MFE, name doesn’t matter
try:
sampling_freq = sr
except:
sampling_freq = 16000
implementation_version = 4
draw_graphs = False
# Set the desired settings/params
frame_length = 0.02
frame_stride = 0.01
num_filters = 40
fft_length = 256
low_frequency = 0
high_frequency = None
noise_floor_db = -52
# Generate the features
rounded_audio_array = generate_features(implementation_version, draw_graphs, samples, axes, sampling_freq,
frame_length, frame_stride, num_filters, fft_length, low_frequency, high_frequency, 0, noise_floor_db)['features']
4.predict_result
interpreter = tf.lite.Interpreter(
model_path=“ei-arc-classifier-tensorflow-lite-float32-model.lite”)
interpreter.allocate_tensors()
input_details = interpreter.get_input_details()
output_details = interpreter.get_output_details()
input_data = np.array(processed_features, dtype=np.float32)
interpreter.set_tensor(input_details[0]['index'], [input_data])
interpreter.invoke()
output_data = interpreter.get_tensor(output_details[0]['index'])
output_data = output_data[0]
# print(output_data)
categories = ["connect", "disconnect", "longsit", "lost", "noise"]
formatted_results = {category: f"{value:.5f}" for category,
value in zip(categories, output_data)}
Go through 1-4, the result is not right.
Copy raw features from web then run 3 and 4, the result is right.
Using step 2 to generate raw features then paste into example-standalone-inferencing example code, the result is also right.
It seems the step2 is wrong,but works on C example code.
Any idea how can I make the code right?