CEMA brings together a multidisciplinary consortium of epidemiologists, infectious disease specialists, clinicians, mathematicians, statisticians, computer scientists and data scientists using data-driven approaches to control infectious diseases and improve health in Kenya and the African Continent. It bridges disciplines across different schools within the University of Nairobi (UoN) and the private sector to deliver timely analysis to inform policy to tackle infectious diseases and improve health outcomes. Read more about CEMA from their official website.
In this repo, you will find a machine learning model that I was assigned to come up with using TensorFlow.
Create a machine learning model that is able to classify whether a blood smear is either uninfected or parasitized with the Plasmodium parasite.
For this task, I used a sample* of thin blood smear slide images of segmented cells data from the simplified Kaggle Malaria Dataset that was obtained under licenses by The National Institutes of Health.
After checking & organizing the cell images based on whether they were uninfected or parasitized, the following step was to pre-process the images (both uninfected & parasitized cell images) using TensorFlow's ImageDataGenerator in rescaling, augmentation, & resizing.
I proceeded with designing a Convolutional Neural Network (CNN) that utilized convolutional layers for feature extraction, pooling layers for dimensionality reduction, & connected layers for classification. The number of layers, filters, & activation functions were hyperparameters that can be tuned for optimal performance.
The training data was used to train the built model using the model.fit which iterated through the training data while adjusting the model's internal parameters to minimize the loss function which indicates how well the model classifies. A validation set was used to monitor the model's performance during training thus reducing overfitting (in case there was).
The trained model was then subjected to evaluation using the metrics: accuracy, precision, and recall - These metrics provided a comprehensive understanding to me on the model's effectiveness in classifying the blood smear as either uninfected or parasitized.
This' a basic framework for building a machine learning model for malaria parasite classification, its effectiveness depends heavily on the quality & size of the training data - Utilizing more complex architectures can potentially enhance performance.
For this task, I utilized Google's online platform - Google Colab, because of the free GPU access which significantly sped up my model training & testing which are computationally intensive. If you prefer to perform this offline, then there are few modifications that should be made to a few sections in the general structure for the model to be successful. Here are the steps:
i). Download the "datasets" folder & save it in your local device.
If you prefer to use the entire non-sampled dataset, you can download the "Kaggle Simplified Dataset" or the "NIH Original Dataset".
ii). Download the CEMA ML.ipynb file from this repository & save it locally.
iii). Using your IDE, open the CEMA ML.ipynb & make the following changes:
- delete the
GOOGLE DRIVE MOUNTINGcell block because you already have the data saved locally. - delete the
EXECUTING SHELL COMMANDScell block in theENVIRONMENT SET-UPsection if you already have the listed libraries installed, but if you lack then remove the!mark from the codes in the cell block & execute the cell. - in the
IMAGE PATH DEFINITIONSsection, rename the data paths to that of your device where your respective folders & subfolders are located.
iv). Execute the other model sections without making any changes (unless you are making modifications).
sample* - In an ordered manner, I sampled the first few images for this task based on the availability of my computing resources (laptop's CPU & clock speeds). Training the model with the whole set of data would require a computer with very high processing speed and power. In case you need the whole data for that, you can obtain it from NIH Official Website
If it happens that when you try to open the CEMA ML.ipynb file & an error message "An error occurred [...] Using nbformat v[...] and nbconvert v[...]" occurs - a rare issue with how GitHub tries to render Jupyter Notebook's that's being opened, there's a possibility that GitHub might have rendering issues with the specific versions.
The most convenient way to solve that issue is by using the Github Developer Option.