def display_digit_and_predictions(image: np.ndarray, label: int, pred: int, pred_one_hot: np.ndarray) -> None: """Display the MNIST image and the predicted class as a title. Parameters ---------- image : np.ndarray MNIST image. label : int True class number. pred : int Predicted class number. pred_one_hot : np.ndarray One-hot encoded prediction. """ if image.shape == (784, ): image = image.reshape((28, 28)) _, axs = plt.subplots(1, 2) pred_one_hot = [[int(round(val * 100.0, 4)) for val in pred_one_hot[0]]] # Table data labels = [i for i in range(10)] axs[0].axis('tight') axs[0].axis('off') axs[0].table(cellText=pred_one_hot, colLabels=labels, loc="center") # Image data axs[1].imshow(image, cmap=plt.get_cmap('gray_r')) # General plotting settings plt.figure_title('Label: %d, Pred: %d' % (label, pred)) plt.show()
def display_digit(image, label=None, pred_label=None): """Display the Digit from the image. If the Label and PredLabel is given, display it too. """ if image.shape == (784, ): image = image.reshape((28, 28)) label = np.argmax(label, axis=0) if pred_label is None and label is not None: plt.figure_title('Label: %d' % (label)) elif label is not None: plt.figure_title('Label: %d, Pred: %d' % (label, pred_label)) plt.imshow(image, cmap=plt.get_cmap('gray_r')) plt.show()
def display_digit_and_predictions(image, label, pred, pred_one_hot): if image.shape == (784, ): image = image.reshape((28, 28)) _, axs = plt.subplots(1, 2) pred_one_hot = [[int(round(val * 100.0, 4)) for val in pred_one_hot[0]]] # Table data labels = [i for i in range(10)] axs[0].axis('tight') axs[0].axis('off') axs[0].table(cellText=pred_one_hot, colLabels=labels, loc="center") # Image data axs[1].imshow(image, cmap=plt.get_cmap('gray_r')) # General plotting settings plt.figure_title('Label: %d, Pred: %d' % (label, pred)) plt.show()
def display_digit(image: np.ndarray, label: np.ndarray = None, pred_label: np.ndarray = None) -> None: """Display the MNIST image. If the *label* and *label* is given, these are also displayed. Parameters ---------- image : np.ndarray MNIST image. label : np.ndarray, optional One-hot encoded true label, by default None pred_label : np.ndarray, optional One-hot encoded prediction, by default None """ if image.shape == (784, ): image = image.reshape((28, 28)) label = np.argmax(label, axis=0) if pred_label is None and label is not None: plt.figure_title('Label: %d' % (label)) elif label is not None: plt.figure_title('Label: %d, Pred: %d' % (label, pred_label)) plt.imshow(image, cmap=plt.get_cmap('gray_r')) plt.show()