tensorflow / hub

A library for transfer learning by reusing parts of TensorFlow models.
https://tensorflow.org/hub
Apache License 2.0
3.48k stars 1.66k forks source link

Bug: Why is the TensorFlow audio classification tutorial no longer providing accurate predictions? #921

Open austrisu opened 2 months ago

austrisu commented 2 months ago

What happened?

I've been experimenting with TensorFlow by following the tutorial available here. However, I noticed that the model's predictions seem to be inaccurate. Specifically, when I run the example in Google Colab, the predictions are off.

The tutorial mentions that the audio prediction should work as expected, but the graph provided here shows that the predictions are significantly incorrect.

I checked the Wayback Machine and found that this example was working correctly two years ago (link). It seems like it hasn't been functioning as intended since then.

My question is: Am I missing something, or is there a way to run this example correctly to generate a model that can accurately predict voice commands? Or could this issue be related to changes in TensorFlow versions?

Relevant code

x = data_dir/'no/01bb6a2a_nohash_0.wav'
x = tf.io.read_file(str(x))
x, sample_rate = tf.audio.decode_wav(x, desired_channels=1, desired_samples=16000,)
x = tf.squeeze(x, axis=-1)
waveform = x
x = get_spectrogram(x)
x = x[tf.newaxis,...]

prediction = model(x)
x_labels = ['no', 'yes', 'down', 'go', 'left', 'up', 'right', 'stop']
plt.bar(x_labels, tf.nn.softmax(prediction[0]))
plt.title('No')
plt.show()

display.display(display.Audio(waveform, rate=16000))

Relevant log output

https://www.tensorflow.org/static/tutorials/audio/simple_audio_files/output_zRxauKMdhofU_1.png

tensorflow_hub Version

0.13.0.dev (unstable development build)

TensorFlow Version

2.8 (latest stable release)

Other libraries

No response

Python Version

3.x

OS

Linux

austrisu commented 2 months ago

Commit 2 years ago works corectly https://github.com/tensorflow/docs/blob/563659de0a6fd338395035d207ca4eb9b8544834/site/en/tutorials/audio/simple_audio.ipynb