<jupyter_start><jupyter_text>1st training:  Setup: `x = vgg_19.output        x = Flatten()(x)        x = Dense(50, activation = 'relu')(x)        x = Dropout(0.35)(x)        x = Dense(20, activation = 'relu')(x)        predictions = Dense(n_classes, activation = 'softmax')(x)`       batch size = 64number of epochs = 45learning rate = 1e-5 with `ReduceLROnPlateau` + `EarlyStopping`training time: 539.04 s $\approx 8$ mintest accuracy: 0.6750 (slight overfit)------------------------------------------------------------------------------------------------------------------2nd training: Setup: `x = vgg_19.output        x = Flatten()(x)        x = Dense(30, activation = 'relu')(x)        x = Dropout(0.35)(x)        x = Dense(20, activation = 'relu')(x)        predictions = Dense(n_classes, activation = 'softmax')(x)`         batch size = 64number of epochs = 45learning rate = 1e-5 with `ReduceLROnPlateau` + `EarlyStopping`training time: 608.35 s $\approx 10$ mintest accuracy: 0.7109 (slightly overfit)------------------------------------------------------------------------------------------------------------------3rd training:Setup: `x = vgg_19.output        x = Flatten()(x)        x = Dense(30, activation = 'relu')(x)        x = Dropout(0.4)(x)        x = Dense(20, activation = 'relu')(x)        predictions = Dense(n_classes, activation = 'softmax')(x)`         batch size = 64number of epochs = 45learning rate = 1e-5 with `ReduceLROnPlateau` + `EarlyStopping`training time: 1014.34 s $\approx 17$ mintest accuracy: 0.7234 (underfit)<jupyter_code>print(len(train.labels) // batch_size)
score = model.evaluate(test, steps = len(test.labels) // batch_size, verbose = 0)
print('Test loss: %.4f' % score[0])
print('Test accuracy: %.4f' % score[1])
acc = history.history['accuracy']
val_acc = history.history['val_accuracy']
loss = history.history['loss']
val_loss = history.history['val_loss']
n_epochs = range(len(acc))

# Plot accuracy
plt.plot(n_epochs, acc, label = 'Training accuracy')
plt.plot(n_epochs, val_acc, label = 'Validation accuracy')
plt.title('3rd training')
plt.xlabel('Epochs')
plt.ylabel('Accuracy')
plt.legend(loc = 'best')
plt.savefig('VGG19_3rd_training_t1ce_flair_sagittal_acc.png', dpi = 300)
plt.show()

# Plot loss
plt.plot(n_epochs, loss, label = 'Training loss')
plt.plot(n_epochs, val_loss, label = 'Validation loss')
plt.title('3rd training')
plt.xlabel('Epochs')
plt.ylabel('Loss')
plt.legend(loc = 'best')
plt.savefig('VGG19_3rd_training_t1ce_flair_sagittal_loss.png', dpi = 300)
plt.show()
# Get rounded predictions
y_pred = np.argmax(model.predict(test), axis = 1) 

# Get true labels
y_true = test.classes

# Plot confusion matrix
cm = confusion_matrix(y_true, y_pred)

#ax = sns.heatmap(cm, annot = True, cmap = 'Blues')
ax = sns.heatmap(cm / np.sum(cm), annot = True, fmt = '.2%', cmap = 'PuBu') # viridis, YlGnBu
ax.set_xlabel('\nPredicted values')
ax.set_ylabel('Actual values ');
# list must be in alphabetical order
ax.xaxis.set_ticklabels(['Grade 2','Grade 3', 'Grade 4'])
ax.yaxis.set_ticklabels(['Grade 2','Grade 3', 'Grade 4'])
plt.savefig('3rd_Training_CM_t1ce_flair_sagittal.png', dpi = 300)
plt.show()
# Print classification report
print(classification_report(y_true, y_pred))

# Save the classification report
clsf_report = pd.DataFrame(classification_report(y_true = y_true, y_pred = y_pred, output_dict = True)).transpose()
clsf_report.to_csv('Classification Report-3rd Training on t1_flair sagittal.csv', index = True)
# for fancy LaTeX style plots
from matplotlib import rc
import matplotlib.pylab as plt

rc('font', **{'family': 'serif', 'serif': ['Computer Modern']})
rc('text', usetex = True)

x = plt.linspace(0, 20)
plt.plot(x, plt.sin(x))
plt.xlabel(r"$x$", size = 20)
plt.ylabel(r"$\sin(x)$", size = 20)
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.2069688236835211, 'fraction_numerical': 0.03301021744825779, 'mean_word_length': 3.513002364066194, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '31122', 'license': 'MIT', 'n_tokens_mistral': 1452, 'n_tokens_neox': 1321, 'n_words': 309, 'path': 'source/VGG19/modality_combos/VGG19_pretrained_t1_flair_sagittal.ipynb', 'repo_name': 'Eleftheria94/MScThesis', 'size': '3817'}