运行CNN的每一层

时间:2019-01-24 17:40:35

标签: python keras conv-neural-network

我需要运行以下模型的每一层。我能够运行该模型,但在运行以下模型的每一层时都需要帮助。

代码:

    from keras.models import Sequential
    from keras.layers import Dense, Conv2D, MaxPooling2D, Dropout, 
    Flatten

    def createModel():
        model = Sequential()
        model.add(Conv2D(32, (3, 3), padding='same', activation='relu', 
        input_shape=input_shape))
        model.add(Conv2D(32, (3, 3), activation='relu'))
        model.add(MaxPooling2D(pool_size=(2, 2)))
        model.add(Dropout(0.25))

        model.add(Conv2D(64, (3, 3), padding='same', activation='relu'))
        model.add(Conv2D(64, (3, 3), activation='relu'))
        model.add(MaxPooling2D(pool_size=(2, 2)))
        model.add(Dropout(0.25))

        model.add(Conv2D(64, (3, 3), padding='same', activation='relu'))
        model.add(Conv2D(64, (3, 3), activation='relu'))
        model.add(MaxPooling2D(pool_size=(2, 2)))
        model.add(Dropout(0.25))

        model.add(Flatten())
        model.add(Dense(512, activation='relu'))
        model.add(Dropout(0.5))
        model.add(Dense(nClasses, activation='softmax'))

        return model

谢谢!

0 个答案:

没有答案