If i get the below error what should my input tensor look like to the inverse mel scale function:

inv_mel = torchaudio.transforms.InverseMelScale(n_stft=1025)


TypeError Traceback (most recent call last)

in ()
2 plt.imshow(s)
3 inv_mel = torchaudio.transforms.InverseMelScale(n_stft=1025)
----> 4 inv_mel(s)

1 frames

/usr/local/lib/python3.7/dist-packages/torchaudio/ in forward(self, melspec)
388 “”"
389 # pack batch
→ 390 shape = melspec.size()
391 melspec = melspec.view(-1, shape[-2], shape[-1])

TypeError: ‘int’ object is not callable

Based on the error message it seems that you are using a np.array instead of a tensor, as the former returns an int from the .size attribute:

x = np.random.randn(10)
> TypeError: 'int' object is not callable

x = torch.randn(10)
> torch.Size([10])

so you might want to use tensors.

Hey, Patrick thanks for getting back. When I use a tensor then i get the following error. I am bit confused what the input should look like given an mel spectrogram of shape: torch.Size([288, 432, 4])

AssertionError Traceback (most recent call last)

in ()
8 inv_mel = torchaudio.transforms.InverseMelScale(n_stft=1023)
----> 9 inv_mel(sample)

1 frames

/usr/local/lib/python3.7/dist-packages/torchaudio/ in forward(self, melspec)
394 freq, _ = self.fb.size() # (freq, n_mels)
395 melspec = melspec.transpose(-1, -2)
→ 396 assert self.n_mels == n_mels
398 specgram = torch.rand(melspec.size()[0], time, freq, requires_grad=True,


I guess the input shape might be wrong.
From the docs:

  • n_mels (int, optional) – Number of mel filterbanks. (Default: 128)
  • melspec (Tensor) – A Mel frequency spectrogram of dimension (…, n_mels, time)

Based on this it seems the n_mels argument is set to 128 by default, while your input tensor has a value of 432 in this dimension.

Hey Patrick, so my input tensor can be of shape torch.Size([288, 432, 4]) so what do you think my input tensor shape should be in this case?

Why are there three dots here?: A Mel frequency spectrogram of dimension (…, n_mels, time)
does it imply something?


The three dots should indicate additional dimensions while the last two dimensions would represent n_mels and time.
Could you set n_mels to 432 in InverseMelScale as it should work:

inv_mel = torchaudio.transforms.InverseMelScale(n_stft=1023, n_mels=432)
x = torch.randn(288, 432, 4)
out = inv_mel(x)

Hey Patrick,
I actually tried the above step you mentioned before by setting n_mels= 432 and then my cell (jupyter nb) ran for a very long time with no outputs.

I think a long runtime is expected, since InverseMelScale uses SGD to solve the mapping.
From the docs:

Solve for a normal STFT from a mel frequency STFT, using a conversion matrix. This uses triangular filter banks.
It minimizes the euclidian norm between the input mel-spectrogram and the product between the estimated spectrogram and the filter banks using SGD.

Corresponding lines of code.

You could change the tolerance to stop the optimization earlier, if needed.

Hey Patrick, thanks for getting back. I will try it out again :grinning: