I have developed a robust model that utilizes transfer learning and the powerful ResNet50V2 architecture to effectively classify chest X-ray images into two categories: pneumonia and normal. This model demonstrates high accuracy and generalizability, making it a promising tool for assisting in pneumonia diagnosis.
Model Description
The ResNet50V2:
ResNet50V2 is a deep convolutional neural network (CNN) architecture, part of the ResNet (Residual Networks) family. It's known for its depth, utilizing residual blocks that help address the vanishing gradient problem during training. The "V2" signifies an improvement over the original ResNet50, incorporating tweaks to enhance performance.
Transfer Learning:
Transfer learning involves leveraging a pre-trained model's knowledge on a large dataset and applying it to a different but related task. For our use case, ResNet50V2, which has been trained on a diverse dataset, is adapted to classify pneumonia-related images.
Image Classification:
The core task of the model is to categorize images into two classes: "affected by pneumonia" and "normal." This binary classification is crucial for diagnosing medical conditions based on visual information in images.
Model Training:
During training, the pre-trained ResNet50V2 model is used as a feature extractor. The existing weights are frozen, preventing further training on the original dataset, and a new classifier tailored to this specific task is added. This new classifier is trained using the labeled dataset of pneumonia and normal images.
Loss Function and Optimization:
To guide the training process, a loss function is employed to measure the difference between predicted and actual labels. Common choices for image classification tasks include categorical cross-entropy. An optimizer, such as stochastic gradient descent (SGD) or Adam. In our case we have used Adam as our optimier of choice, which is used to adjust the model's weights based on the calculated loss.
Evaluation:
The model's performance is assessed using a separate dataset not seen during training. Metrics like accuracy, precision, recall, and F1-score are often used to gauge how well the model generalizes to new, unseen data.
Deployment:
Once the model demonstrates satisfactory performance, it can be deployed for real-world use. This involves integrating it into a system or application where it can receive new images, make predictions, and aid in the diagnosis of pneumonia.
This tool is used to assist medical professional in cross-validation of the diagnosis
Out-of-Scope Use
This model is in no form or way to replace an actual medical professional but only in assist them
Bias, Risks, and Limitations
The model cant handle 4d images such as CT scans
How to Get Started with the Model
import tensorflow as tf
from tensorflow import keras
from keras import models
model = load_model('/path/to/model')
model.evaluate('/path/to/image')
Training Details
Training Data
Downloading the dataset from kaggle
split the data into 3 parts
train
test
val
code to split into 25% 75% split of training data
# Creating Val folder
os.chdir('datasets/chest_xray/chest_xray/')
if os.path.isdir('val/NORMAL') is False:
os.makedirs('val/NORMAL')
os.makedirs('val/PNEUMONIA')
# Moving Images from train folder to val folder
source = 'chest_xray/train/PNEUMONIA/'
dest = 'datasets/chest_xray/chest_xray/val/PNEUMONIA'
files = os.listdir(source)
np_of_files = len(files) // 25
for file_name in random.sample(files, np_of_files):
shutil.move(os.path.join(source, file_name), dest)
# Moving Normal Images from train folder to val folder
source = 'datasets/chest_xray/chest_xray/train/NORMAL/'
dest = 'datasets/chest_xray/chest_xray/val/NORMAL'
files = os.listdir(source)
np_of_files = len(files) // 25
for file_name in random.sample(files, np_of_files):
shutil.move(os.path.join(source, file_name), dest)
Training Procedure
The training of the data requires ResNet50V2 to start as the base model and then using further layers to extract more information and to help in classification