Example #1
0
    def f(notes, style):
        time_steps = int(notes.get_shape()[1])

        # TODO: Experiment with when to apply conv
        note_octave = TimeDistributed(
            Conv1D(OCTAVE_UNITS, 2 * OCTAVE, padding='same'))(notes)
        #for
        #note_octave =
        note_octave = Activation('tanh')(note_octave)
        note_octave = Dropout(dropout)(note_octave)

        # Create features for every single note.
        note_features = Concatenate()([
            Lambda(pitch_pos_in_f(time_steps))(notes),
            Lambda(pitch_class_in_f(time_steps))(notes),
            Lambda(pitch_bins_f(time_steps))(notes), note_octave
            #TimeDistributed(RepeatVector(NUM_NOTES))(beat)
        ])

        x = note_features

        # [batch, notes, time, features]
        x = Permute((2, 1, 3))(x)

        # Apply LSTMs
        for l in range(TIME_AXIS_LAYERS):
            # Integrate style
            style_proj = Dense(int(x.get_shape()[3]))(style)
            style_proj = TimeDistributed(RepeatVector(NUM_NOTES))(style_proj)
            style_proj = Activation('tanh')(style_proj)
            style_proj = Dropout(dropout)(style_proj)
            style_proj = Permute((2, 1, 3))(style_proj)
            x = Add()([x, style_proj])

            x = TimeDistributed(LSTM(TIME_AXIS_UNITS,
                                     return_sequences=True))(x)
            x = Dropout(dropout)(x)

        # [batch, time, notes, features]
        return Permute((2, 1, 3))(x)
Example #2
0
    def f(notes, beat, style):
        time_steps = int(notes.get_shape()[1])

        # TODO: Experiment with when to apply conv
        note_octave = TimeDistributed(Conv1D(OCTAVE_UNITS, 2 * OCTAVE, padding='same'))(notes)
        note_octave = Activation('tanh')(note_octave)
        note_octave = Dropout(dropout)(note_octave)

        # Create features for every single note.
        note_features = Concatenate()([
            Lambda(pitch_pos_in_f(time_steps))(notes),
            Lambda(pitch_class_in_f(time_steps))(notes),
            Lambda(pitch_bins_f(time_steps))(notes),
            note_octave,
            TimeDistributed(RepeatVector(NUM_NOTES))(beat)
        ])

        x = note_features

        # [batch, notes, time, features]
        x = Permute((2, 1, 3))(x)

        # Apply LSTMs
        for l in range(TIME_AXIS_LAYERS):
            # Integrate style
            style_proj = Dense(int(x.get_shape()[3]))(style)
            style_proj = TimeDistributed(RepeatVector(NUM_NOTES))(style_proj)
            style_proj = Activation('tanh')(style_proj)
            style_proj = Dropout(dropout)(style_proj)
            style_proj = Permute((2, 1, 3))(style_proj)
            x = Add()([x, style_proj])

            x = TimeDistributed(LSTM(TIME_AXIS_UNITS, return_sequences=True))(x)
            x = Dropout(dropout)(x)

        # [batch, time, notes, features]
        return Permute((2, 1, 3))(x)
Example #3
0
def block_warp(block_name,input_layer,filters,kernal_size=3, dilation_rate=1,depthfilter=4,stride=1):
    def conv_block(input_layer,filters,k=3):
        y = Conv3D(filters=filters, kernel_size=k, padding='same')(input_layer)
        y = BatchNormalization()(y)
        y = Activation('relu')(y)
        return y

    if block_name == 'conv':
        y = conv_block(input_layer,filters)
        y = conv_block(y,filters)

    elif block_name == 'dialtion':
        y = Conv3D(filters=filters, kernel_size=kernal_size, padding='same', dilation_rate=dilation_rate)(input_layer)
        y = BatchNormalization()(y)
        y = Activation('relu')(y)

    elif block_name == 'deconv':
        y = Conv3DTranspose(filters=filters,kernel_size=3,strides=2,padding='same')(input_layer)
        y = BatchNormalization()(y)
        y = Activation('relu')(y)

    elif block_name == 'time_conv':
        y = TimeDistributed(Conv2D(filters=filters,kernel_size=3,padding='same'))(input_layer)
        y = TimeDistributed(BatchNormalization())(y)
        y = TimeDistributed(Activation('relu'))(y)

    elif block_name == 'time_deconv':
        y = TimeDistributed(Conv2DTranspose(filters=filters,kernel_size=3,padding='same',strides=2))(input_layer)
        y = TimeDistributed(BatchNormalization())(y)
        y = TimeDistributed(Activation('relu'))(y)

    elif block_name == 'inception':
        filters = filters//4

        c1 = conv_block(input_layer,filters,1)

        c3 = conv_block(input_layer,filters,1)
        c3 = conv_block(c3,filters,3)

        c5 = MaxPool3D(pool_size=3,padding='same',strides=1)(input_layer)
        c5 = conv_block(c5,filters,3)


        c7 = conv_block(input_layer,filters,1)
        c7 = conv_block(c7, filters, 3)
        c7 = conv_block(c7, filters, 3)

        y = concatenate([c1,c3,c5,c7])
        # c_all = BatchNormalization()(c_all)
        # y = Activation('relu')(c_all)
    elif block_name == 'sep':
        input_layer = Permute((4,1,2,3))(input_layer)
        sz = input_layer.get_shape()
        shape = tuple(int(sz[i]) for i in range(1, 5))
        input_layer = Reshape(shape+(1,))(input_layer)
        conv1 = TimeDistributed(Conv3D(filters=depthfilter,kernel_size=kernal_size,padding='same',strides=stride))(input_layer)
        conv1 = Permute((2,3,4,1,5))(conv1)
        sz = conv1.get_shape()
        shape = tuple(int(sz[i]) for i in range(1, 4))
        conv1 = Reshape(shape+(-1,))(conv1)
        conv1 = Conv3D(filters=filters,kernel_size=1,padding='same')(conv1)
        conv1 = BatchNormalization()(conv1)
        y = Activation('relu')(conv1)

    else:
        raise ValueError("layer error")
    return y