I have saved a model as torch script, to calculate mel spectrograms. Saving the model, and using the model at python gives no error and works as expected. However when I try to use model in c++ with libtorch I have received the following error, which is unintuitive for me. I would be happy, if one explains what is wrong and how to fix it. Thanks

RuntimeError: stft(CUDAFloatType[3708000, 1], n_fft=400, hop_length=80, win_length=400, window=CUDAFloatType{[400]}, normalized=0, onesided=1, return_complex=1) : expected 0 < n_fft < 1, but got n_fft=400

]

It would appear that the input might not have the right shape (should it be `1x3708000`

or even `1x1x3708000`

or something like this? If so, you need to use torch::Tensor::permute or somesuch).

For me, making a habit of checking the input shapes and possible a small portion of the tensor (say slicing the first 5 elements in each dimension) has reduced a great deal of confusion with the outputs when moving between Python and C++.

Best regards

Thomas

1 Like

Thanks this indeed is the problem. Input was not in expected shape.

1 Like