I am trying to run the TFlite audio classification notebook, but swap out the birds dataset and use the ravdess speech emotion dataset instead. I reshaped the ravdess folder structure to match the birds dataset structure which is:
ravdess
├ Train
| ├ Anger
| ├ Surprise
| ├ Calm
| ├ Sad
| ├ Fearful
| ├ Happy
| ├ Neutral
| ├ Disgust
├ Test
| ├ Anger
| ├ Surprise
| ├ Calm
| ├ Sad
| ├ Fearful
| ├ Happy
| ├ Neutral
| ├ Disgust
There are 8 classes instead of the 5 for the bird's dataset, but my dataset and the birds have the same folder structure, just a different number of classes as subfolders.
Here is my code for the model, which is taken straight from the notebook:
!sudo apt -y install libportaudio2
!pip install tflite-model-maker
import tensorflow as tf
import tflite_model_maker as mm
from tflite_model_maker import audio_classifier
import os
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import itertools
import glob
import random
from IPython.display import Audio, Image
from scipy.io import wavfile
print(f"TensorFlow Version: {tf.__version__}")
print(f"Model Maker Version: {mm.__version__}")
# I decided to download the zip, and unzip the file, because sometimes attempting to # train models that have dataloaded from google drive is slow.
!unzip /content/ravdess_data-20221005T170225Z-001.zip
ravdess_dataset_folder = "/content/ravdess_data"
data_dir = ravdess_dataset_folder
spec = audio_classifier.YamNetSpec(
keep_yamnet_and_custom_heads=True,
frame_step=3 * audio_classifier.YamNetSpec.EXPECTED_WAVEFORM_LENGTH,
frame_length=6 * audio_classifier.YamNetSpec.EXPECTED_WAVEFORM_LENGTH)
train_data = audio_classifier.DataLoader.from_folder(
spec, os.path.join(data_dir, 'train'), cache=True)
train_data, validation_data = train_data.split(0.8)
test_data = audio_classifier.DataLoader.from_folder(
spec, os.path.join(data_dir, 'test'), cache=True)
batch_size = 5
epochs = 100
print('Training the model')
model = audio_classifier.create(
train_data,
spec,
validation_data,
batch_size=batch_size,
epochs=epochs)
This is the error I am getting:
InvalidArgumentError Traceback (most recent call last)
<ipython-input-46-a3613f172d24> in <module>
8 validation_data,
9 batch_size=batch_size,
---> 10 epochs=epochs)
4 frames
/usr/local/lib/python3.7/dist-packages/tensorflow_examples/lite/model_maker/core/task/audio_classifier.py in create(cls, train_data, model_spec, validation_data, batch_size, epochs, model_dir, do_train, train_whole_model)
137 train_whole_model=train_whole_model)
138 if do_train:
--> 139 task.train(train_data, validation_data, epochs, batch_size)
140 return task
141
/usr/local/lib/python3.7/dist-packages/tensorflow_examples/lite/model_maker/core/task/audio_classifier.py in train(self, train_data, validation_data, epochs, batch_size)
55 train_ds,
56 validation_ds,
---> 57 callbacks=self._keras_callbacks(self.model_spec.model_dir))
58
59 def create_model(self, num_classes, train_whole_model):
/usr/local/lib/python3.7/dist-packages/tensorflow_examples/lite/model_maker/core/task/model_spec/audio_spec.py in run_classifier(self, model, epochs, train_ds, validation_ds, **kwargs)
490
491 hist = model.fit(
--> 492 train_ds, validation_data=validation_ds, epochs=epochs, **kwargs)
493 return hist
494
/usr/local/lib/python3.7/dist-packages/keras/utils/traceback_utils.py in error_handler(*args, **kwargs)
65 except Exception as e: # pylint: disable=broad-except
66 filtered_tb = _process_traceback_frames(e.__traceback__)
---> 67 raise e.with_traceback(filtered_tb) from None
68 finally:
69 del filtered_tb
/usr/local/lib/python3.7/dist-packages/tensorflow/python/eager/execute.py in quick_execute(op_name, num_outputs, inputs, attrs, ctx, name)
53 ctx.ensure_initialized()
54 tensors = pywrap_tfe.TFE_Py_Execute(ctx._handle, device_name, op_name,
---> 55 inputs, attrs, num_outputs)
56 except core._NotOkStatusException as e:
57 if name is not None:
InvalidArgumentError: Graph execution error:
2 root error(s) found.
(0) INVALID_ARGUMENT: Data too short when trying to read string
[[{{node DecodeWav}}]]
[[IteratorGetNext]]
[[categorical_crossentropy/softmax_cross_entropy_with_logits/Shape_2/_6]]
(1) INVALID_ARGUMENT: Data too short when trying to read string
[[{{node DecodeWav}}]]
[[IteratorGetNext]]
0 successful operations.
0 derived errors ignored. [Op:__inference_train_function_59314]
Things that I have tried so far to fix this:
- Check for empty files. I iterated over all my audio files to find any empty files. There were no empty files. InvalidArgumentError: Data too short when trying to read string [[{{node DecodeWav}}]] [Op:IteratorGetNext]
- Using the local version of the data, rather than pulling from google drive.
- Experimenting with the batch size and number of epochs.
- Searched stack overflow for similar problems. What I read is that it has to do with empty files, which I checked for, or people had to add another layer to fix the number of classes. However, I am not sure how to do this on the tflite model. Furthermore, before the error occurs, tf does report that it is training to predict 8 classes. Invalid Argument Error / Graph Execution Error