Skip to content

Commit

Permalink
Uses epsilon to deal with empty audio
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlGao4 committed Nov 14, 2023
1 parent 8cdc821 commit 350745c
Showing 1 changed file with 3 additions and 18 deletions.
21 changes: 3 additions & 18 deletions demucs/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,24 +264,9 @@ def separate_tensor(
"""
if sr is not None and sr != self.samplerate:
wav = convert_audio(wav, sr, self._samplerate, self._audio_channels)
if wav.max() == wav.min():
self._callback( # type: ignore
_replace_dict(
self._callback_arg,
("state", "end"),
("model_idx_in_bag", (len(self._model.models) - 1)
if isinstance(self._model, BagOfModels) else 0),
("shift_idx", self._shifts - 1),
("segment_offset", wav.shape[1]),
("audio_length", wav.shape[1]),
("models", len(self._model.models) if isinstance(self._model, BagOfModels)
else 1)
)
)
return wav, {name: (wav / len(self._model.sources)) for name in self._model.sources}
ref = wav.mean(0)
wav -= ref.mean()
wav /= ref.std()
wav /= ref.std() + 1e-8
out = apply_model(
self._model,
wav[None],
Expand All @@ -299,9 +284,9 @@ def separate_tensor(
)
if out is None:
raise KeyboardInterrupt
out *= ref.std()
out *= ref.std() + 1e-8
out += ref.mean()
wav *= ref.std()
wav *= ref.std() + 1e-8
wav += ref.mean()
return (wav, dict(zip(self._model.sources, out[0])))

Expand Down

0 comments on commit 350745c

Please sign in to comment.