Enrollments closing soon for Post Graduate Certificate Program in Applied Data Science & AI By IIT Roorkee | 3 Seats Left
Apply NowLogin using Social Account
     Continue with GoogleLogin using your credentials
Let us define the model for the classification of data set A that we have created previously.
Later the trained weights of this model will be used for the classification task of data B.
Create a keras neural network as follows:
Add keras.layers.Flatten
to flatten the input image to the model.
Add 5 dense layers with n_hidden
number of neurons and selu
activation function.
Add a final dense layer with 8 neurons and softmax
activation function(for classifying 8 classes of data).
model_A = keras.models.Sequential()
model_A.add(keras.layers.Flatten(input_shape=[28, 28]))
for n_hidden in (300, 100, 50, 50, 50):
model_A.add(keras.layers.Dense(n_hidden, activation="selu"))
model_A.add(keras.layers.Dense(8, activation="softmax"))
Define the compiling part of the model:
Set "sparse_categorical_crossentropy"
as loss.
Set keras.optimizers.SGD(lr=1e-3)
as optimizer.
model_A.compile(loss= << your code comes here >>,
optimizer= << your code comes here >>,
metrics=["accuracy"])
Now train model_A
on X_train_A
and y_train_A
for 5 epochs , and validation_data=(X_valid_A, y_valid_A)
using model_A.fit
.
history = << your code comes here >>(X_train_A, y_train_A, epochs=5,
validation_data=(X_valid_A, y_valid_A))
Save the model_A
we created.
model_A.save("my_model_A.h5")
Taking you to the next exercise in seconds...
Want to create exercises like this yourself? Click here.
Note - Having trouble with the assessment engine? Follow the steps listed here
Loading comments...