Throat Disease Detection

Replace  this line in Model.py

history = model.fit(training_data, validation_data=validation_data, epochs = 20, callbacks=callbacks_list)

with this one

history = model.fit(training_data, validation_data=validation_data, epochs = 50, callbacks=callbacks_list)

2nd Make a new File in directory  as confusion matrix.py    and add this code in it

import numpy as np
import matplotlib.pyplot as plt
import tensorflow as tf
from sklearn.metrics import confusion_matrix, classification_report, accuracy_score
import seaborn as sns

# Load the trained model
model = tf.keras.models.load_model(‘model_weights.h5’)

# Load test dataset
test_data = tf.keras.preprocessing.image_dataset_from_directory(
    ‘data/test’,
    seed=42,
    image_size=(250, 250),
    batch_size=100,  # Set batch size to 1 for prediction
    color_mode=’rgb’,
    shuffle=False  # Keep the order to compute the confusion matrix
)

# Define class names for the two classes
class_names = [‘Healthy Throat’, ‘Infected Throat’]

# Extract true labels and make predictions
true_labels = []
predicted_labels = []

for images, labels in test_data:
    true_labels.extend(labels.numpy())
    predictions = model.predict(images)
    predicted_labels.extend(np.argmax(predictions, axis=1))

# Calculate the accuracy
accuracy = accuracy_score(true_labels, predicted_labels)

# Calculate the confusion matrix
confusion_mtx = confusion_matrix(true_labels, predicted_labels)

# Create a figure and axis for the heatmap
plt.figure(figsize=(8, 6))
sns.set(font_scale=1.2)  # Adjust the font size as needed

# Create the heatmap
sns.heatmap(confusion_mtx, annot=True, fmt=’d’, cmap=’Blues’, cbar=False,
            xticklabels=class_names, yticklabels=class_names)

# Set labels and a title
plt.xlabel(‘Predicted Labels’)
plt.ylabel(‘True Labels’)
plt.title(‘Confusion Matrix’)

# # Display the plot
plt.show()

# Print the accuracy and classification report
print(f’Accuracy: {accuracy:.4f}’)
class_report = classification_report(true_labels, predicted_labels, target_names=class_names)
print(class_report)

Updated 2024 FYP Projects

X