Enrollments Open for Online Instructor-Led Training for Big Data Engineering and Machine Learning | Use Coupon END15 for Extra 15% OffEnroll Now
Let us build a neural network with Dense layers for this classification problem.
keras.layers.Flatten : Flattens the input.
keras.layers.Dense(300, activation="relu") : Just your regular densely-connected NN layer with 300 neurons and
relu activation function.
Why do we need clear_session?
It is useful when you're creating multiple models in successions, such as during hyperparameter search or cross-validation. Each model you train adds nodes (potentially numbering in the thousands) to the graph. Eventually, models will become slower and slower to train, and you may also run out of memory. Clearing the session removes all the nodes left over from previous models, freeing memory and preventing slowdown.
Note: Makesure to write the following code snippets in separate code cells.
Let us first clear the session:
Now, let us build the neural network as follows:
model = keras.models.Sequential([ keras.layers.Flatten(input_shape=[28, 28]), keras.layers.Dense(300, activation="relu"), keras.layers.Dense(100, activation="relu"), keras.layers.Dense(10, activation="softmax") ])
Let us view the layers of model.
Let us view the summary of
Let us plot the arcitecture of
model and save it into
keras.utils.plot_model(model, "my_fashion_mnist_model.png", show_shapes=True)
sgd optimizer by using
keras.optimizers.SGD and setting the
sgd = << your code comes here >>(learning_rate=0.01)
Now let us define the
compile part of the model as below:
model.compile(loss="sparse_categorical_crossentropy", optimizer=sgd, metrics=["accuracy"])
We have set
accuracy as a performance evaluation metric. Also, we set
sparse_categorical_crossentropy as the loss function, as we have the labels which are not one-hot vectors but the integers. More here.
No hints are availble for this assesment
Answer is not availble for this assesment
Note - Having trouble with the assessment engine? Follow the steps listed here