Skip to content
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 expect mel-band oriented tensors instead of time-oriented ones #39

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

roedoejet
Copy link
Member

@roedoejet roedoejet commented Oct 30, 2024

Copy link

semanticdiff-com bot commented Oct 30, 2024

Review changes with  SemanticDiff

Changed Files
File Status
  hfgl/utils.py  53% smaller
  hfgl/cli.py  12% smaller

Copy link
Collaborator

@SamuelLarkin SamuelLarkin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make the code a little bit more readable

Comment on lines +153 to +186
if time_oriented:
data = data.transpose(0, 1)
data_size = data.size()
if (
checkpoint["hyper_parameters"]["config"]["preprocessing"]["audio"]["n_mels"]
not in data_size
):
raise ValueError(
f"Your model expects a spectrogram of dimensions [K (Mel bands), T (frames)] where K == {checkpoint['hyper_parameters']['config']['preprocessing']['audio']['n_mels']} but you provided a tensor of size {data_size}"
)
if (
data_size[0]
!= checkpoint["hyper_parameters"]["config"]["preprocessing"]["audio"]["n_mels"]
):
raise ValueError(
f"We expected the first dimension of your Mel spectrogram to correspond with the number of Mel bands declared by your model ({checkpoint['hyper_parameters']['config']['preprocessing']['audio']['n_mels']}). Instead, we found you model has the dimensions {data_size}. If your spectrogram is time-oriented, please re-run this command with the '--time-oriented' flag."
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if time_oriented:
data = data.transpose(0, 1)
data_size = data.size()
if (
checkpoint["hyper_parameters"]["config"]["preprocessing"]["audio"]["n_mels"]
not in data_size
):
raise ValueError(
f"Your model expects a spectrogram of dimensions [K (Mel bands), T (frames)] where K == {checkpoint['hyper_parameters']['config']['preprocessing']['audio']['n_mels']} but you provided a tensor of size {data_size}"
)
if (
data_size[0]
!= checkpoint["hyper_parameters"]["config"]["preprocessing"]["audio"]["n_mels"]
):
raise ValueError(
f"We expected the first dimension of your Mel spectrogram to correspond with the number of Mel bands declared by your model ({checkpoint['hyper_parameters']['config']['preprocessing']['audio']['n_mels']}). Instead, we found you model has the dimensions {data_size}. If your spectrogram is time-oriented, please re-run this command with the '--time-oriented' flag."
)
if time_oriented:
data = data.transpose(0, 1)
data_size = data.size()
config_n_mels = checkpoint["hyper_parameters"]["config"]["preprocessing"]["audio"]["n_mels"]
if (config_n_mels not in data_size):
raise ValueError(
f"Your model expects a spectrogram of dimensions [K (Mel bands), T (frames)] where K == {config_n_mels} but you provided a tensor of size {data_size}"
)
if (data_size[0] != config_n_mels):
raise ValueError(
f"We expected the first dimension of your Mel spectrogram to correspond with the number of Mel bands declared by your model ({config_n_mels}). Instead, we found you model has the dimensions {data_size}. If your spectrogram is time-oriented, please re-run this command with the '--time-oriented' flag."
)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, please accept this suggestion, the code is quite hard to read.

Copy link
Member

@joanise joanise left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please accept Sam's change request, otherwise this looks fine.

Comment on lines +153 to +186
if time_oriented:
data = data.transpose(0, 1)
data_size = data.size()
if (
checkpoint["hyper_parameters"]["config"]["preprocessing"]["audio"]["n_mels"]
not in data_size
):
raise ValueError(
f"Your model expects a spectrogram of dimensions [K (Mel bands), T (frames)] where K == {checkpoint['hyper_parameters']['config']['preprocessing']['audio']['n_mels']} but you provided a tensor of size {data_size}"
)
if (
data_size[0]
!= checkpoint["hyper_parameters"]["config"]["preprocessing"]["audio"]["n_mels"]
):
raise ValueError(
f"We expected the first dimension of your Mel spectrogram to correspond with the number of Mel bands declared by your model ({checkpoint['hyper_parameters']['config']['preprocessing']['audio']['n_mels']}). Instead, we found you model has the dimensions {data_size}. If your spectrogram is time-oriented, please re-run this command with the '--time-oriented' flag."
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, please accept this suggestion, the code is quite hard to read.

!= checkpoint["hyper_parameters"]["config"]["preprocessing"]["audio"]["n_mels"]
):
raise ValueError(
f"We expected the first dimension of your Mel spectrogram to correspond with the number of Mel bands declared by your model ({checkpoint['hyper_parameters']['config']['preprocessing']['audio']['n_mels']}). Instead, we found you model has the dimensions {data_size}. If your spectrogram is time-oriented, please re-run this command with the '--time-oriented' flag."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This warning message is good, probably giving the user the feedback I was asking for in the top-level PR.

@joanise
Copy link
Member

joanise commented Dec 9, 2024

Note: you'll need to rebase, and solve the merge conflict: we now have to use shell_complete, not autocompletion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants