#NoPayJan Offer - Access all CloudxLab Courses for free between 1st to 31st Jan

  Enroll Now >>

Defining some Utility Functions

  • We shall define 3 utility functions which we will be using further:

    • rounded_accuracy: we define this function to get the rounded accuracy by calculating the accuracies using the rounded values of the predicted value and the actual value.

    • plot_image : used to plot the given image

    • show_reconstructions : we shall use this function to show how our trained model is able to reconstruct the validation data.


  • keras.metrics.binary_accuracy : calculates how often predictions matches binary labels. It computes the mean accuracy rate across all predictions for binary classification problems.

  • plt.imshow : Display data as an image

  • plt.axis("off") : It does not display the axis.

  • plt.subplot : Add a subplot to the current figure.

  • Define the rounded_accuracy:

    def rounded_accuracy(y_true, y_pred):
        return keras.metrics.binary_accuracy(tf.round(y_true), tf.round(y_pred))
  • Define the plot_image function:

    def plot_image(image):
        plt.imshow(image, cmap="binary")
  • Define the show_reconstructions:

    def show_reconstructions(model, images=X_valid, n_images=5):
        reconstructions = model.predict(images[:n_images])
        fig = plt.figure(figsize=(n_images * 1.5, 3))
        for image_index in range(n_images):
            plt.subplot(2, n_images, 1 + image_index)
            plt.subplot(2, n_images, 1 + n_images + image_index)

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

Loading comments...