This function compiles and returns a Keras model. Should be passed to KerasClassifier in the Keras scikit-learn API.
()
| 14 | |
| 15 | # build function for the Keras' scikit-learn API |
| 16 | def create_keras_model(): |
| 17 | """ |
| 18 | This function compiles and returns a Keras model. |
| 19 | Should be passed to KerasClassifier in the Keras scikit-learn API. |
| 20 | """ |
| 21 | |
| 22 | model = Sequential() |
| 23 | model.add(Conv2D(32, kernel_size=(3, 3), activation='relu', input_shape=(28, 28, 1))) |
| 24 | model.add(Conv2D(64, (3, 3), activation='relu')) |
| 25 | model.add(MaxPooling2D(pool_size=(2, 2))) |
| 26 | model.add(Dropout(0.25)) |
| 27 | model.add(Flatten()) |
| 28 | model.add(Dense(128, activation='relu')) |
| 29 | model.add(Dropout(0.5)) |
| 30 | model.add(Dense(10, activation='softmax')) |
| 31 | |
| 32 | model.compile(loss='categorical_crossentropy', optimizer='adadelta', metrics=['accuracy']) |
| 33 | |
| 34 | return model |
| 35 | |
| 36 | |
| 37 | # create the classifier |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…