python 时间分布在Keras的CNN + LSTM

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 时间分布在Keras的CNN + LSTM相关的知识,希望对你有一定的参考价值。

def defModel():
    model = Sequential()
    #Izda.add(TimeDistributed(
    #    Convolution2D(40,3,3,border_mode='same'), input_shape=(sequence_lengths, 1,8,10)))
    model.add(
        TimeDistributed(
            Conv2D(32, (7, 7), padding='same', strides = 2),
            input_shape=(None, 540, 960, 2)))
    model.add(Activation('relu'))

    model.add(TimeDistributed(Conv2D(64, (5, 5), padding='same', strides = 2)))
    model.add(Activation('relu'))

    #model.add(TimeDistributed(MaxPooling2D((2,2), data_format = 'channels_first', name='pool1')))
    
    model.add(TimeDistributed(Conv2D(128, (5, 5), padding='same', strides = 2)))
    model.add(Activation('relu'))    
    
    model.add(TimeDistributed(Conv2D(128, (3, 3), padding='same')))
    model.add(Activation('relu'))
    
    model.add(TimeDistributed(Conv2D(256, (3, 3), padding='same', strides = 2)))
    model.add(Activation('relu'))
    
    model.add(TimeDistributed(Conv2D(256, (3, 3), padding='same')))
    model.add(Activation('relu'))
    
    model.add(TimeDistributed(Conv2D(256, (3, 3), padding='same', strides = 2)))
    model.add(Activation('relu'))    

    model.add(TimeDistributed(Conv2D(256, (3, 3), padding='same')))
    model.add(Activation('relu'))
    
    model.add(TimeDistributed(Conv2D(512, (3, 3), padding='same', strides = 2)))
    model.add(Activation('relu'))    
    #model.add(TimeDistributed(MaxPooling2D((2,2), data_format = 'channels_first', name='pool1')))    
    
    #model.add(TimeDistributed(Conv2D(32, (1, 1), data_format = 'channels_first')))
    #model.add(Activation('relu'))    
    
    model.add(TimeDistributed(Flatten()))
    
    #model.add(TimeDistributed(Dense(512, name="first_dense" )))
    
    #model.add(LSTM(num_classes, return_sequences=True))
    model.add(LSTM(512 , return_sequences=True))
    model.add(LSTM(512))
    model.add(Dense(128))
    model.add(Dense(3))

    model.compile(loss='mean_squared_error', optimizer='adam')  #,
    #metrics=['accuracy'])
    plot_model(model, to_file='model/model.png')
    plot_model(model, to_file='model/model_detail.png', show_shapes=True)
    return model

以上是关于python 时间分布在Keras的CNN + LSTM的主要内容,如果未能解决你的问题,请参考以下文章

使用Python,Keras和TensorFlow训练第一个CNN

python Keras建立CNN模型的模板

你如何在 Python 中使用 Keras LeakyReLU?

python KerasによるCNNの実装例

python keras_cnn_mnist.py

python keras_cnn_cifar10.py