I tried to run the code and this appear as an error.
ValueError: Trying to load a model of incompatible/unknown type. 'C:Userspm23821AppDataLocalTemptfhub_modules9616fd04ec2360621642ef9455b84f4b668e219e' contains neither 'saved_model.pb' nor 'saved_model.pbtxt'
It’s my first time using tensorflow and models, so I don’t know what I need to do to work my code.
The goal is to find a difference between the sounds, When the emergency siren (police, fire department, and hospitals) is detected, it needs to appear as if it has been identified. When the sound of a home siren or a parrot is heard, it should appear that it has not been identified.
# Carrega o modelo YAMNet
model = hub.load('https://tfhub.dev/google/yamnet/1')
# Carrega os nomes das classes do YAMNet
def load_class_names(csv_path='yamnet_class_map.csv'):
class_map = pd.read_csv(csv_path, sep=',', header=None)
class_names = class_map[1].tolist()
return class_names
class_names = load_class_names()
# Função para capturar áudio do microfone
def record_audio(duration=5, fs=16000): # Aumentei a duração para 5 segundos
recording = sd.rec(int(duration * fs), samplerate=fs, channels=1, dtype='float32')
sd.wait()
return recording.flatten()
# Função para prever a classe do áudio
def predict_sound(audio_data):
scores, embeddings, spectrogram = model(audio_data)
prediction = np.argmax(scores, axis=1)[0]
return class_names[prediction]
# Loop principal
while True:
print("Escutando...")
audio_data = record_audio()
audio_data /= np.max(np.abs(audio_data))
predicted_class = predict_sound(audio_data)
print("Classe de som prevista:", predicted_class)
if "/m/012n7d" in predicted_class or "/m/03j1ly" in predicted_class or "/m/03kmc9" in predicted_class:
print("Sirene detectada!")
else:
print("Não é uma sirene.")
time.sleep(1) # Pausa de 1 segundo antes da próxima gravação
Lohine is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.