-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor!: change model to output mel-band oriented tensors instead of time-oriented ones #94
Open
roedoejet
wants to merge
3
commits into
main
Choose a base branch
from
dev.ap/513
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -106,7 +106,7 @@ def get_filename( | |
speaker: str, | ||
language: str, | ||
include_global_step: bool = False, | ||
) -> Path: | ||
) -> str: | ||
# We don't truncate or alter the filename here because the basename is | ||
# already truncated/cleaned in cli/synthesize.py | ||
name_parts = [basename, speaker, language, self.file_extension] | ||
|
@@ -115,7 +115,7 @@ def get_filename( | |
path = self.save_dir / self.sep.join(name_parts) | ||
# synthesizing spec allows nested outputs so we may need to make subdirs | ||
path.parent.mkdir(parents=True, exist_ok=True) | ||
return path | ||
return str(path) | ||
|
||
|
||
class PredictionWritingSpecCallback(PredictionWritingCallbackBase): | ||
|
@@ -159,7 +159,9 @@ def on_predict_batch_end( # pyright: ignore [reportIncompatibleMethodOverride] | |
outputs["tgt_lens"], | ||
): | ||
torch.save( | ||
data[:unmasked_len].cpu(), | ||
data[:unmasked_len] | ||
.cpu() | ||
.transpose(0, 1), # save tensors as [K (bands), T (frames)] | ||
self.get_filename(basename, speaker, language), | ||
) | ||
|
||
|
@@ -409,7 +411,7 @@ def synthesize_audio(self, outputs): | |
|
||
sr: int | ||
wavs: np.ndarray | ||
output_value = outputs[self.output_key] | ||
output_value = outputs[self.output_key].transpose(1, 2) | ||
if output_value is not None: | ||
wavs, sr = synthesize_data( | ||
output_value, self.vocoder_model, self.vocoder_config | ||
|
@@ -419,21 +421,15 @@ def synthesize_audio(self, outputs): | |
f"{self.output_key} does not exist in the output of your model" | ||
) | ||
|
||
# wavs: [B (batch_size), T (samples)] | ||
# wavs: [B (batch_size), C (channels), T (samples)] | ||
assert ( | ||
wavs.ndim == 2 | ||
), f"The generated audio contained more than 2 dimensions. First dimension should be B(atch) and the second dimension should be T(ime) in samples. Got {wavs.shape} instead." | ||
assert "output" in outputs and outputs["output"] is not None | ||
assert wavs.shape[0] == outputs["output"].size( | ||
wavs.ndim == 3 | ||
), f"The generated audio did not contain 3 dimensions. First dimension should be B(atch) and the second dimension should be C(hannels) and third dimension should be T(ime) in samples. Got {wavs.shape} instead." | ||
assert self.output_key in outputs and outputs[self.output_key] is not None | ||
assert wavs.shape[0] == outputs[self.output_key].size( | ||
0 | ||
), f"You provided {outputs['output'].size(0)} utterances, but {wavs.shape[0]} audio files were synthesized instead." | ||
|
||
# synthesize 16 bit audio | ||
# we don't do this higher up in the inference methods | ||
# because tensorboard logs require audio data as floats | ||
if (wavs >= -1.0).all() & (wavs <= 1.0).all(): | ||
wavs = wavs * self.config.preprocessing.audio.max_wav_value | ||
wavs = wavs.astype("int16") | ||
), f"You provided {outputs[self.output_key].size(0)} utterances, but {wavs.shape[0]} audio files were synthesized instead." | ||
|
||
return wavs, sr | ||
|
||
def on_predict_batch_end( # pyright: ignore [reportIncompatibleMethodOverride] | ||
|
@@ -445,7 +441,7 @@ def on_predict_batch_end( # pyright: ignore [reportIncompatibleMethodOverride] | |
_batch_idx: int, | ||
_dataloader_idx: int = 0, | ||
): | ||
from scipy.io.wavfile import write | ||
import torchaudio | ||
|
||
logger.trace("Generating waveform...") | ||
|
||
|
@@ -459,11 +455,14 @@ def on_predict_batch_end( # pyright: ignore [reportIncompatibleMethodOverride] | |
wavs, | ||
outputs["tgt_lens"], | ||
): | ||
write( | ||
torchaudio.save( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the change of audio writer function related to this PR, or just an unrelated improvement? I assume you've tested and you can confirm this works well? |
||
self.get_filename( | ||
basename, speaker, language, include_global_step=True | ||
), | ||
sr, | ||
# the vocoder output includes padding so we have to remove that | ||
wav[: (unmasked_len * self.output_hop_size)], | ||
sr, | ||
format="wav", | ||
encoding="PCM_S", | ||
bits_per_sample=16, | ||
) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this happen due to a user error (like providing the wrong kind of input file), or is this strictly due to a programmer error? If the latter, OK, if the former, I don't like using assert.