in realbook/layers/signal.py [0:0]
def build(self, input_shape: tf.TensorShape) -> None:
if input_shape.rank > 3 or input_shape.rank <= 1:
raise ValueError(
"realbook.layers.signal.Istft received an input shape of "
f"{input_shape}, but only supports inputs shaped "
"like (num_frames, num_bins) or (num_batches, num_frames, num_bins)."
)
self.window = _create_padded_window(self.window_fn, self.window_length, self.fft_length)(
self.fft_length
) # type: ignore
self.window_sum = librosa_filters.window_sumsquare( # type: ignore
window=self.window.numpy(),
n_frames=input_shape[0] if input_shape.rank == 2 else input_shape[1],
win_length=self.window_length,
n_fft=self.fft_length,
hop_length=self.hop_length,
dtype=self.dtypes_type.as_numpy_dtype,
)
self.window_sum = tf.constant(
np.where(
self.window_sum > np.finfo(self.dtypes_type.as_numpy_dtype).tiny,
self.window_sum,
np.ones_like(self.window_sum),
),
self.dtypes_type.real_dtype,
)
self.slice_op = tf.keras.layers.Lambda(lambda x: x)
if self.center:
if input_shape.rank == 2: # unbatched
self.slice_op = tf.keras.layers.Lambda(
lambda x: x[int(self.fft_length // 2) : -int(self.fft_length // 2)]
)
else: # batched
self.slice_op = tf.keras.layers.Lambda(
lambda x: x[:, int(self.fft_length // 2) : -int(self.fft_length // 2)]
)