Esempio n. 1
0
    def fft_layer(self, data_x):
        # Creating FFT
        filter_num = 100
        data_input = data_x
        data_x_padded = keras.layers.ZeroPadding1D((0, 1))(data_input)
        data_x_squeez = keras.layers.Lambda(
            lambda x: keras.backend.squeeze(x, 2),
            output_shape=lambda shape: (shape[0], shape[1]),
            name='data_x_squeez')(data_x_padded)

        data_x_rfft = keras.layers.Lambda(lambda x: tf.signal.rfft(x),
                                          name='data_x_rfft')(data_x_squeez)

        data_x_rfft_abs = keras.layers.Lambda(
            lambda x: tf.math.abs(x), name='data_x_rfft_abs')(data_x_rfft)
        data_x_rfft_angle_complex = keras.layers.Lambda(
            lambda x: tf.math.exp(tf.complex(0.0, tf.math.angle(x))),
            name='data_x_rfft_angle_complex')(data_x_rfft)
        # Learning Filters 800*100 100
        rfft_process = data_x_rfft_abs
        rfft_process_dense = keras.layers.Dense(
            units=filter_num,
            activation="sigmoid",
            use_bias=False,
            kernel_initializer=keras.initializers.Identity())(rfft_process)
        # rfft_process_dense = layers.AddSingletonDepth()(rfft_process_dense)
        rfft_process_dense = keras.layers.RepeatVector(
            rfft_process.shape[-1])(rfft_process_dense)

        rfft_process = layers.AddSingletonDepth()(data_x_rfft_abs)
        rfft_process_filter = layers.BigFilter(
            units=filter_num, name="freq_filters")(rfft_process)

        rfft_process = keras.layers.Multiply(name='rfft_process')(
            [rfft_process_dense, rfft_process_filter])
        rfft_process = keras.layers.Convolution1D(1, 1)(rfft_process)
        # rfft_process = self.activation(rfft_process)
        #Recontruction
        rfft_process_complex = keras.layers.Lambda(
            lambda x: tf.complex(tf.math.abs(x), 0.0),
            name='rfft_process_complex')(rfft_process)
        new_rfft = keras.layers.Multiply(name='new_rfft')([
            layers.AddSingletonDepth()(data_x_rfft_angle_complex),
            rfft_process_complex
        ])

        new_rfft = keras.layers.Lambda(lambda x: keras.backend.squeeze(x, -1))(
            new_rfft)
        data_out = keras.layers.Lambda(lambda x: tf.signal.irfft(x),
                                       name='IRFFT')(new_rfft)
        data_out = keras.layers.Lambda(
            lambda x: keras.backend.expand_dims(x, -1))(data_out)
        data_out = tf.keras.layers.Cropping1D(cropping=(0, 1),
                                              name="data_fft_put")(data_out)
        return data_out
    def build_model(self):

        data_input = keras.engine.Input(
                shape=(self.input_length,),
                name='data_input')

        data_expanded = layers.AddSingletonDepth()(data_input)

        data_out = keras.layers.Convolution1D(self.config['model']['filters']['depths']['res'],
                                              self.config['model']['filters']['lengths']['res'], padding='same',
                                              use_bias=False,
                                              name='initial_causal_conv')(data_expanded)

        skip_connections = []
        res_block_i = 0
        for stack_i in range(self.num_stacks):
            layer_in_stack = 0
            for dilation in self.dilations:
                res_block_i += 1
                data_out, skip_out = self.dilated_residual_block(data_out, res_block_i, layer_in_stack, dilation, stack_i)
                if skip_out is not None:
                    skip_connections.append(skip_out)
                layer_in_stack += 1

        data_out = keras.layers.Add()(skip_connections)

        data_out = self.activation(data_out)

        data_out = keras.layers.Convolution1D(self.config['model']['filters']['depths']['final'][0],
                                              self.config['model']['filters']['lengths']['final'][0],
                                              padding='same',
                                              use_bias=False)(data_out)

        data_out = self.activation(data_out)
        data_out = keras.layers.Convolution1D(self.config['model']['filters']['depths']['final'][1],
                                              self.config['model']['filters']['lengths']['final'][1], padding='same',
                                              use_bias=False)(data_out)

        data_out = keras.layers.Convolution1D(3, 1)(data_out)

        data_out_vocals = layers.Slice((Ellipsis, slice(0, 1)), (self.padded_target_field_length, 1),
                                       name='slice_data_output_1')(data_out)
        data_out_drums = layers.Slice((Ellipsis, slice(1, 2)), (self.padded_target_field_length, 1),
                                              name='slice_data_output_2')(data_out)
        data_out_bass = layers.Slice((Ellipsis, slice(2, 3)), (self.padded_target_field_length, 1),
                                      name='slice_data_output_3')(data_out)

        data_out_vocals = keras.layers.Lambda(lambda x: keras.backend.squeeze(x, 2),
                                              output_shape=lambda shape: (shape[0], shape[1]), name='data_output_1')(
            data_out_vocals)

        data_out_drums = keras.layers.Lambda(lambda x: keras.backend.squeeze(x, 2),
                                              output_shape=lambda shape: (shape[0], shape[1]), name='data_output_2')(
            data_out_drums)

        data_out_bass = keras.layers.Lambda(lambda x: keras.backend.squeeze(x, 2),
                                              output_shape=lambda shape: (shape[0], shape[1]), name='data_output_3')(
            data_out_bass)

        return keras.engine.Model(inputs=[data_input], outputs=[data_out_vocals, data_out_drums, data_out_bass])
Esempio n. 3
0
    def build_model(self):

        data_input = keras.engine.Input(
                shape=(self.input_length,),
                name='data_input')

        condition_input = keras.engine.Input(shape=(self.condition_input_length,),
                                             name='condition_input')
        data_expanded = layers.AddSingletonDepth()(data_input)
        data_input_target_field_length = layers.Slice(
            (slice(self.samples_of_interest_indices[0], self.samples_of_interest_indices[-1] + 1, 1), Ellipsis),
            (self.padded_target_field_length,1),
            name='data_input_target_field_length')(data_expanded)
        data_out = keras.layers.Conv1D(self.config['model']['filters']['depths']['res'],
                                       self.config['model']['filters']['lengths']['res'], padding='same',
                                       use_bias=False,
                                       name='initial_causal_conv')(data_expanded)

        condition_out = keras.layers.Dense(self.config['model']['filters']['depths']['res'],
                                           name='initial_dense_condition',
                                           use_bias=False)(condition_input)
        condition_out = keras.layers.RepeatVector(int(self.input_length),
                                                  name='initial_condition_repeat')(condition_out)
        data_out = keras.layers.Add(name='initial_data_condition_merge')([data_out, condition_out])

        skip_connections = []
        res_block_i = 0
        for stack_i in range(self.num_stacks):
            layer_in_stack = 0
            for dilation in self.dilations:
                res_block_i += 1
                data_out, skip_out = self.dilated_residual_block(data_out, condition_input, res_block_i, layer_in_stack, dilation, stack_i)
                if skip_out is not None:
                    skip_connections.append(skip_out)
                layer_in_stack += 1

        data_out = keras.layers.Add()(skip_connections)
        data_out = self.activation(data_out)

        data_out = keras.layers.Conv1D(self.config['model']['filters']['depths']['final'][0],
                                              self.config['model']['filters']['lengths']['final'][0],
                                              padding='same',
                                              bias=False)(data_out)

        condition_out = keras.layers.Dense(self.config['model']['filters']['depths']['final'][0],
                                           bias=False,
                                           name='penultimate_conv_1d_condition')(condition_input)

        condition_out = keras.layers.RepeatVector(self.padded_target_field_length,
                                                  name='penultimate_conv_1d_condition_repeat')(condition_out)
        data_out = keras.layers.Add(name='penultimate_conv_1d_condition_merge')([data_out, condition_out])

        data_out = self.activation(data_out)
        data_out = keras.layers.Conv1D(self.config['model']['filters']['depths']['final'][1],
                                              self.config['model']['filters']['lengths']['final'][1], padding='same',
                                              use_bias=False)(data_out)

        condition_out = keras.layers.Dense(self.config['model']['filters']['depths']['final'][1], use_bias=False,
                                           name='final_conv_1d_condition')(condition_input)

        condition_out = keras.layers.RepeatVector(self.padded_target_field_length,
                                                  name='final_conv_1d_condition_repeat')(condition_out)

        data_out = keras.layers.Add(name='final_conv_1d_condition_merge')([data_out, condition_out])

        data_out = keras.layers.Conv1D(1, 1)(data_out)

        data_out_speech = data_out
        data_out_noise = layers.Subtract(name='subtract_layer')([data_input_target_field_length, data_out_speech])

        data_out_speech = keras.layers.Lambda(lambda x: keras.backend.squeeze(x, 2),
                                              output_shape=lambda shape: (shape[0], shape[1]), name='data_output_1')(
            data_out_speech)

        data_out_noise = keras.layers.Lambda(lambda x: keras.backend.squeeze(x, 2),
                                              output_shape=lambda shape: (shape[0], shape[1]), name='data_output_2')(
            data_out_noise)

        return keras.engine.Model(input=[data_input, condition_input], output=[data_out_speech, data_out_noise])
Esempio n. 4
0
    def build_model(self):
        data_input = keras.layers.Input(shape=(
            2,
            self.input_length,
        ),
                                        name='data_input')
        # condition_input = keras.engine.Input(shape=(self.condition_input_length,),
        # name='condition_input')

        data_mix = keras.layers.Lambda(lambda x: keras.backend.sum(x, 1))(
            data_input)
        data_expanded = layers.AddSingletonDepth()(data_mix)

        # data_input_target_field_length = layers.Slice(
        # (slice(self.samples_of_interest_indices[0], self.samples_of_interest_indices[-1] + 1, 1), Ellipsis),
        # (self.padded_target_field_length,1),
        # name='data_input_target_field_length')(data_expanded)

        data_out = keras.layers.Conv1D(
            self.config['model']['filters']['depths']['res'],
            self.config['model']['filters']['lengths']['res'],
            padding='same',
            use_bias=False,
            name='initial_causal_conv')(data_expanded)

        # condition_out = keras.layers.Dense(self.config['model']['filters']['depths']['res'],
        # name='initial_dense_condition',
        # bias=False)(condition_input)
        # condition_out = keras.layers.RepeatVector(self.input_length,
        # name='initial_condition_repeat')(condition_out)
        # data_out = keras.layers.Merge(mode='sum', name='initial_data_condition_merge')(
        # [data_out, condition_out])

        skip_connections = []
        res_block_i = 0
        for stack_i in range(self.num_stacks):
            layer_in_stack = 0
            for dilation in self.dilations:
                res_block_i += 1
                data_out, skip_out = self.dilated_residual_block(data_out, res_block_i, \
                                                                 layer_in_stack, dilation, stack_i)
                if skip_out is not None:
                    skip_connections.append(skip_out)
                layer_in_stack += 1

        data_out = keras.layers.Add()(skip_connections)
        data_out = self.activation(data_out)

        data_out = keras.layers.Conv1D(
            self.config['model']['filters']['depths']['final'][0],
            self.config['model']['filters']['lengths']['final'][0],
            padding='same',
            use_bias=False)(data_out)
        # condition_out = keras.layers.Dense(self.config['model']['filters']['depths']['final'][0],
        # bias=False,
        # name='penultimate_conv_1d_condition')(condition_input)

        # condition_out = keras.layers.RepeatVector(self.padded_target_field_length,
        # name='penultimate_conv_1d_condition_repeat')(condition_out)

        # data_out = keras.layers.Merge(mode='sum', name='penultimate_conv_1d_condition_merge')([data_out, condition_out])

        data_out = self.activation(data_out)
        data_out = keras.layers.Conv1D(
            self.config['model']['filters']['depths']['final'][1],
            self.config['model']['filters']['lengths']['final'][1],
            padding='same',
            use_bias=False)(data_out)
        # condition_out = keras.layers.Dense(self.config['model']['filters']['depths']['final'][1], bias=False,
        # name='final_conv_1d_condition')(condition_input)

        # condition_out = keras.layers.RepeatVector(self.padded_target_field_length,
        # name='final_conv_1d_condition_repeat')(condition_out)

        # data_out = keras.layers.Merge(mode='sum', name='final_conv_1d_condition_merge')([data_out, condition_out])

        # data_out = keras.layers.Conv1D(self.n_output, 1)(data_out)
        data_out = keras.layers.Conv1D(
            self.n_output,
            self.config['model']['filters']['lengths']['final'][1],
            padding='same',
            use_bias=False)(data_out)

        out_speech = keras.layers.Lambda(
            lambda x: keras.backend.permute_dimensions(x, (0, 2, 1)),
            name='data_output')(data_out)

        # out_speech_2 = keras.layers.Lambda(lambda x: x[:,:,1],
        # output_shape=lambda shape: (shape[0], shape[1]),
        # name='data_output_2')(data_out)
        ## add discriminator

        return keras.engine.Model(inputs=[data_input], outputs=[out_speech])
Esempio n. 5
0
    def build_model(self):

        data_input = keras.Input(shape=(self.input_length, ),
                                 name='data_input')

        data_expanded = layers.AddSingletonDepth()(data_input)
        data_input_target_field_length = layers.Slice(
            (slice(self.samples_of_interest_indices[0],
                   self.samples_of_interest_indices[-1] + 1, 1), Ellipsis),
            (self.padded_target_field_length, 1),
            name='data_input_target_field_length')(data_expanded)

        data_out = keras.layers.Convolution1D(
            self.config['model']['filters']['depths']['res'],
            self.config['model']['filters']['lengths']['res'],
            padding='same',
            use_bias=False,
            name='initial_causal_conv_1',
            kernel_constraint=keras.constraints.max_norm(30))(data_expanded)

        skip_connections = []
        res_block_i = 0
        for stack_i in range(self.num_stacks):
            layer_in_stack = 0
            for dilation in self.dilations:
                res_block_i += 1
                data_out, skip_out = self.dilated_residual_block(
                    data_out, res_block_i, layer_in_stack, dilation, stack_i)
                if skip_out is not None:
                    skip_connections.append(skip_out)
                layer_in_stack += 1

        data_out = keras.layers.Add()(skip_connections)
        # data_out = keras.layers.Concatenate(axis=2)(skip_connections)
        # data_out = keras.layers.Convolution1D(self.config['model']['filters']['depths']['res'], 1)(data_out)
        data_out = self.activation(data_out)

        data_out = keras.layers.Convolution1D(
            self.config['model']['filters']['depths']['final'][0],
            self.config['model']['filters']['lengths']['final'][0],
            padding='same',
            use_bias=False)(data_out)

        data_out = self.activation(data_out)
        data_out = keras.layers.Convolution1D(
            self.config['model']['filters']['depths']['final'][1],
            self.config['model']['filters']['lengths']['final'][1],
            padding='same',
            use_bias=False)(data_out)

        data_out = keras.layers.Convolution1D(1, 1)(data_out)

        data_out_speech = self.fft_layer(data_out)

        data_out_noise = layers.Subtract(name='subtract_layer')(
            [data_input_target_field_length, data_out_speech])

        data_out_speech = keras.layers.Lambda(
            lambda x: keras.backend.squeeze(x, -1),
            output_shape=lambda shape: (shape[0], shape[1]),
            name='data_output_1')(data_out_speech)
        data_out_noise = keras.layers.Lambda(
            lambda x: keras.backend.squeeze(x, -1),
            output_shape=lambda shape: (shape[0], shape[1]),
            name='data_output_2')(data_out_noise)

        return keras.Model(inputs=[data_input],
                           outputs=[data_out_speech, data_out_noise])