'Why are the print statements not displaying after executing python code?

I am trying to run a AlexNet python code, but the print statements are not displaying in the output. Anyone can tell me why?I have displayed the snippet of the code, but let me know if anything else is needed. I am trying to compare images that is being imported from folder, but when I run the code, I get the graphs that I need, but I also need to display the print functions listed below at the end of the code to be able to get more data that I need.

import matplotlib.pyplot as plt
#Plotting the training and validation loss

f,ax=plt.subplots(1,1) #Creates 2 subplots under 1 column

#Assigning the first subplot to graph training loss and validation loss
ax.plot(AlexNet.history.history['loss'],color='b',label='Training Loss')
ax.plot(AlexNet.history.history['val_loss'],color='r',label='Validation Loss')
plt.legend()
plt.show()
f,ax=plt.subplots(1,1) #Creates 2 subplots under 1 column
#Plotting the training accuracy and validation accuracy
ax.plot(AlexNet.history.history['accuracy'],color='b',label='Training Accuracy')
ax.plot(AlexNet.history.history['val_accuracy'],color='r',label='Validation Accuracy')
plt.legend()
plt.show()


#Defining function for confusion matrix plot
def plot_confusion_matrix(y_true, y_pred, classes,
                          normalize=False,
                          title=None,
                          cmap=plt.cm.Blues):
    if not title:
        if normalize:
            title = 'Normalized confusion matrix'
        else:
            title = 'Confusion matrix, without normalization'

    # Compute confusion matrix
    cm = confusion_matrix(y_true, y_pred)
    if normalize:
        cm = cm.astype('float') / cm.sum(axis=1)[:, np.newaxis]
        print("Normalized confusion matrix")
    else:
        print('Confusion matrix, without normalization')

#Print Confusion matrix
    fig, ax = plt.subplots(figsize=(4,4))
    im = ax.imshow(cm, interpolation='nearest', cmap=cmap)
    ax.figure.colorbar(im, ax=ax)
    # We want to show all ticks...
    ax.set(xticks=np.arange(cm.shape[1]),
           yticks=np.arange(cm.shape[0]),
           xticklabels=classes, yticklabels=classes,
           title=title,
           ylabel='True label',
           xlabel='Predicted label')

    # Rotate the tick labels and set their alignment.
    plt.setp(ax.get_xticklabels(), rotation=45, ha="right",
             rotation_mode="anchor")
    # Loop over data dimensions and create text annotations.
    fmt = '.2f' if normalize else 'd'
    thresh = cm.max() / 2.
    for i in range(cm.shape[0]):
        for j in range(cm.shape[1]):
            ax.text(j, i, format(cm[i, j], fmt),
                    ha="center", color="white"
                if cm[i, j] > thresh else "black")
    plt.tight_layout()
    return ax

np.set_printoptions(precision=2)

#Making prediction
y_pred=AlexNet.predict_classes(x_test)
y_true=np.argmax(y_test,axis=1)

#Plotting the confusion matrix
from sklearn.metrics import confusion_matrix
confusion_mtx=confusion_matrix(y_true,y_pred)

#class_names=['airplane', 'automobile', 'bird', 'cat', 'deer', 'dog', 'frog', 'horse', 'ship', 'truck']
CLASS_NAMES = [f.name for f in os.scandir(imgPath) if f.is_dir()]
class_names=CLASS_NAMES
print(class_names)


print("ypred\n", y_pred)
print("ytrue", y_true)

# Plotting non-normalized confusion matrix
plot_confusion_matrix(y_true, y_pred, classes = class_names,title = 'Confusion matrix, without normalization')
plt.show()
# Plotting normalized confusion matrix
# plot_confusion_matrix(y_true, y_pred, classes=class_names, normalize=True, title='Normalized confusion matrix')
# plt.show()
#Classification Metrics
from sklearn.metrics import accuracy_score, precision_score, recall_score, f1_score, RocCurveDisplay
acc_score = accuracy_score(y_true, y_pred)
print('\n\n\t\t  Accuracy Score: ', str(round((100*acc_score), 2)), '%')
prec_score = precision_score(y_true, y_pred, average = 'macro')
print('   Precision Score Macro: ', str(round((100*prec_score), 2)), '%')
prec_score = precision_score(y_true, y_pred, average = 'micro')
print('   Precision Score Micro: ', str(round((100*prec_score), 2)), '%')
prec_score = precision_score(y_true, y_pred, average = 'weighted')
print('Precision Score Weighted: ', str(round((100*prec_score), 2)), '%')
rec_score = recall_score(y_true, y_pred, average = 'macro')
print('\t\t\tRecall Macro: ', str(round((100*rec_score), 2)), '%')
rec_score = recall_score(y_true, y_pred, average = 'micro')
print('\t\t\tRecall Micro: ', str(round((100*rec_score), 2)), '%')
rec_score = recall_score(y_true, y_pred, average = 'weighted')
print('\t\t Recall Weighted: ', str(round((100*rec_score), 2)), '%')
f_score = f1_score(y_true, y_pred, average = 'macro')
print('\t\t  F1 Score Macro: ', str(round((100*f_score), 2)), '%')
f_score = f1_score(y_true, y_pred, average = 'micro')
print('\t\t  F1 Score Micro: ', str(round((100*f_score), 2)), '%')
f_score = f1_score(y_true, y_pred, average = 'weighted')
print('\t   F1 Score Weighted: ', str(round((100*f_score), 2)), '%')
#print("Evaluation")
#AlexNet.evaluate(x_test, y_test, batch_size=batch_size,verbose=1)

Any help would be appreciated.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source