We'll now build a single model with the Keras library:
- Build a linear stack of layers with the sequential model:
# building a linear stack of layers with the sequential modelmodel = Sequential()model.add(Dense(512, input_shape=(1024,)))model.add(Activation('relu')) model.add(Dense(512))model.add(Activation('relu'))model.add(Dense(10))model.add(Activation('softmax'))
- Compile the model:
# compiling the sequential modelmodel.compile(loss='categorical_crossentropy', metrics=['accuracy'], optimizer='adam')
- Fit the model to the train data and validate it with the test data:
# training the model and saving metrics in historysvhn_model = model.fit(x_train, y_train, batch_size=128, epochs=100, verbose=2, validation_data=(x_test, ...