Ejemplo n.º 1
0
    def call(self, inputs):

        mean = tf.math.reduce_mean(inputs, axis=self.axis, keepdims=True)
        deviation_abs = tf.math.reduce_mean(tf.abs(inputs - mean),
                                            axis=self.axis,
                                            keepdims=True)
        return (inputs - mean) / (deviation_abs + self.epsilon)
Ejemplo n.º 2
0
 def _fft_magnitude(self, inputs):
   """Compute FFT and returns its magnitude."""
   real_spectrum = tf.signal.rfft(inputs, [self.fft_size])
   magnitude_spectrum = tf.abs(real_spectrum)
   if self.magnitude_squared:
     return tf.square(magnitude_spectrum)
   else:
     return magnitude_spectrum
Ejemplo n.º 3
0
    def test_tf_fft_vs_rdft_direct(self):

        signal_size = 64
        # input signal
        signal = np.random.rand(1, signal_size)

        # build rfft model and run it
        input_signal = tf.keras.Input(shape=(signal_size, ), batch_size=1)
        spectrum = tf.signal.rfft(input_signal)
        spectrum = tf.abs(spectrum)
        model = tf.keras.Model(input_signal, spectrum)
        model.summary()
        spectrum_output = model.predict(signal)

        # build rdft model and run it
        input_signal = tf.keras.Input(shape=(signal_size, ), batch_size=1)
        output = magnitude_rdft.MagnitudeRDFT(
            magnitude_squared=False)(input_signal)
        model = tf.keras.Model(input_signal, output)
        model.summary()
        rdft_output = model.predict(signal)

        self.assertAllClose(rdft_output, spectrum_output)