You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
My current project is quite similar to yours, but as I needed another way of getting and sending the audio, I chosed to pick parts of it, and not use it in a Docker container.
But as I use tflite_runtime in the same way as this project, it sometimes completely stops working on invoke() (and any subsequent method, for example if I try to recreate it with tflite.Intepreter()), and I can't even use Ctrl+C to stop the program, I need to kill it.
Do you have any idea why ? My test code is the following :
importtflite_runtime.interpreterastfliteimportglobimportosfromosimportpathimportlibrosaimportnumpyasnpimportsqlite3importtimefromdatetimeimportdatetime, timedeltaDB_FILE=os.getenv("DB_PATH", "/home/mendel/udp/audio_db.db") # path and filename of databaseWAV_PATH=os.getenv("WAV_PATH", "/home/mendel/udp/audio/") # folder with wav filesMODEL_FILE=os.getenv("MODEL_FILE", "/home/mendel/classifier/sound_edgetpu.tflite") # path and filename with model fileLABEL_FILE=os.getenv("LABEL_FILE", "/home/mendel/classifier/labels.txt") #path and filename of associated model class namesAUTO_DELETE=os.getenv("AUTO_DELETE", "false") #if equal to true, files above the threshold will automatically be deleted ct=os.getenv("CERTAINTY_THRESHOLD", "50") # minimum value to consider prediction to be acceptableifct.isnumeric():
CERTAINTY_THRESHOLD=int(ct)
else:
CERTAINTY_THRESHOLD=70# Load labels from a filesound_names= [line.rstrip('\n') forlineinopen(LABEL_FILE)]
print("Loaded {0} labels for model.".format(len(sound_names)))
# just extract the featuresdefextract_features_only(filename):
features=np.empty((0,193))
X, sample_rate=librosa.load(filename)
stft=np.abs(librosa.stft(X))
mfccs=np.mean(librosa.feature.mfcc(y=X, sr=sample_rate, n_mfcc=40).T,axis=0)
chroma=np.mean(librosa.feature.chroma_stft(S=stft, sr=sample_rate).T,axis=0)
mel=np.mean(librosa.feature.melspectrogram(X, sr=sample_rate).T,axis=0)
contrast=np.mean(librosa.feature.spectral_contrast(S=stft, sr=sample_rate).T,axis=0)
tonnetz=np.mean(librosa.feature.tonnetz(y=librosa.effects.harmonic(X), sr=sample_rate).T,axis=0)
ext_features=np.hstack([mfccs,chroma,mel,contrast,tonnetz])
features=np.vstack([features,ext_features])
returnfeaturestry:
interpreter=tflite.Interpreter(model_path=MODEL_FILE, experimental_delegates=[tflite.load_delegate('libedgetpu.so.1')])
exceptValueError:
print("Interpreter error. Is Edge TPU plugged in?")
input_details=interpreter.get_input_details()
output_details=interpreter.get_output_details()
interpreter.allocate_tensors()
FILE="/home/mendel/udp_classifier/audio/1622637563.wav"n=0whileTrue:
predict_x=extract_features_only(FILE)
interpreter.set_tensor(input_details[0]['index'], predict_x.astype(np.float32))
start_time=time.time()
interpreter.invoke()
end_time=time.time()
duration=str(round(1000*(end_time-start_time), 1))
print("Interpreter duration: {} ms".format(duration))
tflite_model_predictions=interpreter.get_tensor(output_details[0]['index'])
# print(tflite_model_predictions[0])# get the indices of the top 2 predictions, invert into descending orderind=np.argpartition(tflite_model_predictions[0], -2)[-2:]
ind[np.argsort(tflite_model_predictions[0][ind])]
ind=ind[::-1]
top_certainty=int(tflite_model_predictions[0,ind[0]] *100)
second_certainty=int(tflite_model_predictions[0,ind[1]] *100)
print("Top guess: ", sound_names[ind[0]], " (", top_certainty, "%)")
print("2nd guess: ", sound_names[ind[1]], " (", second_certainty, "%)")
n+=1print(n)
time.sleep(0.5)
It is supposed to classify the same sound over and over, but it will always freeze after a few iterations (around 10 in my tests). For example, here it stopped after 10 :
(classifier_env) mendel@fun-rabbit:~/udp_classifier$ python test_tflite.py
Loaded 10 labels for model.
Interpreter duration: 10.3 ms
Top guess: dog_bark ( 50 %)
2nd guess: gun_shot ( 21 %)
1
Interpreter duration: 1.5 ms
Top guess: dog_bark ( 50 %)
2nd guess: gun_shot ( 21 %)
2
Interpreter duration: 1.5 ms
Top guess: dog_bark ( 50 %)
2nd guess: gun_shot ( 21 %)
3
Interpreter duration: 1.4 ms
Top guess: dog_bark ( 50 %)
2nd guess: gun_shot ( 21 %)
4
Interpreter duration: 1.3 ms
Top guess: dog_bark ( 50 %)
2nd guess: gun_shot ( 21 %)
5
Interpreter duration: 1.3 ms
Top guess: dog_bark ( 50 %)
2nd guess: gun_shot ( 21 %)
6
Interpreter duration: 1.4 ms
Top guess: dog_bark ( 50 %)
2nd guess: gun_shot ( 21 %)
7
Interpreter duration: 1.4 ms
Top guess: dog_bark ( 50 %)
2nd guess: gun_shot ( 21 %)
8
Interpreter duration: 1.4 ms
Top guess: dog_bark ( 50 %)
2nd guess: gun_shot ( 21 %)
9
Interpreter duration: 1.4 ms
Top guess: dog_bark ( 50 %)
2nd guess: gun_shot ( 21 %)
10
^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^CTerminated
Am I missing something obvious or a library to make it work ? Or maybe it is something in the containers themselves ?
Thank you very much in advance!
The text was updated successfully, but these errors were encountered:
My current project is quite similar to yours, but as I needed another way of getting and sending the audio, I chosed to pick parts of it, and not use it in a Docker container.
But as I use tflite_runtime in the same way as this project, it sometimes completely stops working on
invoke()
(and any subsequent method, for example if I try to recreate it withtflite.Intepreter()
), and I can't even use Ctrl+C to stop the program, I need to kill it.Do you have any idea why ? My test code is the following :
It is supposed to classify the same sound over and over, but it will always freeze after a few iterations (around 10 in my tests). For example, here it stopped after 10 :
Am I missing something obvious or a library to make it work ? Or maybe it is something in the containers themselves ?
Thank you very much in advance!
The text was updated successfully, but these errors were encountered: