`STFT` layer output shape deviates from `STFTTflite` layer in batch dimension
See original GitHub issueUse Case
I want to convert a STFT
layer in my model to a STFTTflite
to deploy it to my mobile device. In the documentation I found that another dimension is added to account for complex numbers. But I also encountered a behaviour that is not documented.
Expected Behaviour
input_shape = (2048, 1) # mono signal
model = keras.models.Sequential() # TFLite incompatible model
model.add(kapre.STFT(n_fft=1024, hop_length=512, input_shape=input_shape))
tflite_model = keras.models.Sequential() # TFLite compatible model
tflite_model.add(kapre.STFTTflite(n_fft=1024, hop_length=512, input_shape=input_shape))
model
has the output shape (None, 3, 513, 1)
. Therefore, tflite_model
should have the output shape (None, 3, 513, 1, 2)
.
Observed Behaviour
The output shape of tflite_model
is (1, 3, 513, 1, 2)
instead of (None, 3, 513, 1, 2)
.
Problem Solution
- If this behaviour is unwanted:
- Change the model output format so that the batch dimension is correctly shaped.
- Otherwise:
- Explain in the documentation why the batch dimension is shaped to
1
. - Explain in the documentation how to include this layer into models which expect the batch dimension to be shaped
None
.
- Explain in the documentation why the batch dimension is shaped to
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
time_frequency_tflite — Kapre 2017 documentation
A Short-time Fourier transform layer (tflite compatible). ... If output_data_format == 'channels_last' , the output shape is (batch, time, freq, channel, ...
Read more >Need tf.signal.rfft op in TFLite · Issue #27303 - GitHub
Changing the output tensor to the pcm tensor instead of stft works fine converter = tf.lite.TFLiteConverter.from_session(sess, [waveform], ...
Read more >Tensorflow STFT Layer - Kaggle
TensorFlow STFT and STFT Inverse Layers. This notebook is based on TensorFlow tutorial. The tutorial is about dealing with Audio data, with the...
Read more >tf.signal.stft | TensorFlow v2.11.0
Computes the [Short-time Fourier Transform][stft] of signals. ... The size of the FFT to apply. If not provided, uses the smallest power of ......
Read more >STFT output shape - PyTorch Forums
Hi,. I am confused about the output shape from STFT. Given print (y.shape) s = torch.stft(y, frame_length=128, hop=32) print (s.shape).
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi,
I can see in the model summary that while the input is
None
theSTFTTflite
layers still have a batch size of 1. So while I would expect this model to convert and run fine (when you provide a batch size of one), you would still need resize the input dimension of the resulting tflite file to have a batch size of 1.E.g. using resize_tensor_input()
Cheers
Paul
Thank you so much for everyone!