Skip to content

Commit bb13820

Browse files
author
Yijia Shao
committed
Update audio_spec.py
Fix the potential "nan" problem of the preprocess_model used by BrowserFftSpec. The preprocess_model will produce "nan" results when input tensors contain too many zero entries. Such inputs are common because there may be delays in recording devices resulting in an empty stream at the beginning of the audio file. This problem can be fixed by adding small Gaussian noise to the inputs before they go through the preprocess_model.
1 parent 5d039b7 commit bb13820

File tree

1 file changed

+2
-1
lines changed
  • tensorflow_examples/lite/model_maker/core/task/model_spec

1 file changed

+2
-1
lines changed

tensorflow_examples/lite/model_maker/core/task/model_spec/audio_spec.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,8 @@ def _split(self, wav, label):
283283
])
284284
def _preprocess(self, x, label):
285285
"""Preprocess the dataset to extract the spectrum."""
286-
# Add small Gaussian noise to the input x to solve the potential "nan" problem of the preprocess_model
286+
# Add small Gaussian noise to the input x
287+
# to solve the potential "nan" problem of the preprocess_model
287288
x = x + 1e-05 * tf.random.normal(x.shape)
288289
# x has shape (1, EXPECTED_WAVEFORM_LENGTH)
289290
spectrum = self._preprocess_model(x)

0 commit comments

Comments
 (0)