Major Concepts

 

Sign-Up/Login to access Several ML Models and also Deploy & Monetize your own ML solutions for free

Malaria Detection

Models Status

Model Overview

INTRODUCTION


Malaria is a life-threatening disease. It’s typically transmitted through the bite of an infected anopheles mosquito. Infected mosquitoes carry the plasmodium parasite. When this mosquito bites you, the parasite is released into your bloodstream. It is considered as an endemic in many parts of the world.


Malaria detection is performed by examining a drop of the patient’s blood, spread out as a “blood smear” (red blood cell) on a microscope slide. This blog focuses on improving malaria detection from such patches segmented from the microscopic images of blood smears by introducing a deep convolutional neural network. Compared to the traditional methods that use tedious hand engineering feature extraction, the proposed method uses deep learning in an end-to-end arrangement that performs both feature extraction and classification directly from the raw segmented patches of the red blood smears.


SYMPTOMS OF MALARIA


A malaria infection is generally characterized by the following signs and symptoms:



  • Fever

  • Chills

  • Headache

  • Nausea and vomiting

  • Muscle pain and fatigue


Other signs and symptoms may include:



  • Sweating

  • Chest or abdominal pain

  • Cough


RISK FACTOR


Malaria is commonly associated with poverty and has a major negative effect on economic development. In Africa, it is estimated to result in losses of US$12 billion a year due to increased healthcare costs, lost ability to work, and negative effects on tourism


How is Malaria diagnosed by pathologists?


Typically Malaria is diagnosed by microscopic examination of blood cells under the supervision of a pathologist. Red blood cells are examined using a microscope using blood films. The pathologists try to find evidence of Malaria using past domain knowledge. Typically, when a cell is infected with Malaria one can see distorted cell shapes which are also accompanied by certain blunt spots in the cell.


PROBLEM STATEMENT


For malaria as well as other microbial infections, manual inspection of thick and thin blood smears by trained microscopists remains the gold standard for parasite detection and stage determination because of its low reagent and instrument cost and high flexibility. Despite manual inspection being extremely low throughout and susceptible to human bias, automatic counting software remains largely unused because of the wide range of variations in brightfield microscopy images. However, a robust automatic counting and cell classification solution would provide enormous benefits due to faster and more accurate quantitative results without human variability; researchers and medical professionals could better characterize stage-specific drug targets and better quantify patient reactions to drugs.


General Outline


Our code template shall perform the following steps:



  1. Importing Libraries

  2. Preliminary Data Processing.

  3. Check the total number of entries

  4. Exploratory Data Analysis (EDA).


Information about the dataset.


The dataset is downloaded from Kaggle from this link — https://www.kaggle.com/iarunava/cell-images-for-detecting-malaria. The dataset was originally taken from the NIH website and uploaded to a Kaggle repository. The dataset contains 27558 cell images. Out of these 27558 images, we have 13779 cell images that are infected by Malaria and another 13779 uninfected images.


Importing Libraries



import os
import random

##Imports for Managing Datasets
import numpy as np
import pandas as pd

##Imports for Data Visualization
import matplotlib.pyplot as plt
from matplotlib.image import imread
import seaborn as sns

 

Data Processing


To start off, we read in our dataset.




train_path = '/content/drive/MyDrive/Dataset/Train'
valid_path = '/content/drive/MyDrive/Dataset/Test'

 


 Exploratory Data Analysis(EDA)


import matplotlib.pyplot as plt
from matplotlib.image import imread
import seaborn as sns
import random
import os

filenames = random.sample(os.listdir('/content/drive/MyDrive/Dataset/Train/Parasite') , 25)

##here we will see 25 images of Parasitized cell images
plt.figure(figsize=(15, 15)) # figure size
for i in range(1, len(filenames)):
row = i
image = imread('/content/drive/MyDrive/Dataset/Train/Parasite/' + filenames[i])
plt.subplot(5, 5, row)
plt.imshow(image)
plt.show()

 


Pre-Processing-Creating CNN Using Scratch And Transfer Learning


import tensorflow as tf
from tensorflow.keras.layers import Input, Lambda, Dense, Flatten,Conv2D
from tensorflow.keras.models import Model
from tensorflow.keras.applications.vgg19 import VGG19
from tensorflow.keras.applications.resnet50 import preprocess_input
from tensorflow.keras.preprocessing import image
from tensorflow.keras.preprocessing.image import ImageDataGenerator,load_img
from tensorflow.keras.models import Sequential
import numpy as np
from glob import glob
import matplotlib.pyplot as plt

for layer in mobilnet.layers:
layer.trainable = False
folders = glob('/content/drive/MyDrive/Dataset/Train*')
x = Flatten()(mobilnet.output)
prediction = Dense(len(folders), activation='softmax')(x)

# create a model object
model = Model(inputs=mobilnet.input, outputs=prediction)
model.summary()

from tensorflow.keras.layers import MaxPooling2D

### Create Model from scratch using CNN
model=Sequential()
model.add(Conv2D(filters=16,kernel_size=2,padding="same",activation="relu",input_shape=(224,224,3)))
model.add(MaxPooling2D(pool_size=2))
model.add(Conv2D(filters=32,kernel_size=2,padding="same",activation ="relu"))
model.add(MaxPooling2D(pool_size=2))
model.add(Conv2D(filters=64,kernel_size=2,padding="same",activation="relu"))
model.add(MaxPooling2D(pool_size=2))
model.add(Flatten())
model.add(Dense(500,activation="relu"))
model.add(Dense(2,activation="softmax"))
model.summary()


#Model execution
model.compile(
loss='categorical_crossentropy',
optimizer='adam',
metrics=['accuracy']
)

# IMage Augmentation
from tensorflow.keras.preprocessing.image import ImageDataGenerator

train_datagen = ImageDataGenerator(rescale = 1./255,
shear_range = 0.2,
zoom_range = 0.2,
horizontal_flip = True)

test_datagen = ImageDataGenerator(rescale = 1./255)


training_set = train_datagen.flow_from_directory('/content/drive/MyDrive/Dataset/Train',
target_size = (224, 224),
batch_size = 32,
class_mode = 'categorical')

test_set = test_datagen.flow_from_directory('/content/drive/MyDrive/Dataset/Test',
target_size = (224, 224),
batch_size = 32,
class_mode = 'categorical')

#Model Training

r = model.fit_generator(
training_set,
validation_data=test_set,
epochs=50,
steps_per_epoch=len(training_set),
validation_steps=len(test_set)
)




# Plotting and checking Accuracy, Loss

plt.plot(r.history['loss'], label='train loss')
plt.plot(r.history['val_loss'], label='val loss')
plt.legend()
plt.show()
plt.savefig('LossVal_loss')
# plot the accuracy
plt.plot(r.history['accuracy'], label='train acc')
plt.plot(r.history['val_accuracy'], label='val acc')
plt.legend()
plt.show()
plt.savefig('AccVal_acc')

0 comments