Project Files added
Browse files- Malaria_Cell_Detection_CNN.ipynb +0 -0
- app.py +37 -0
- deep_learning_pipeline.py +26 -0
- model_resnet152v2.h5 +3 -0
- requirements.txt +3 -0
Malaria_Cell_Detection_CNN.ipynb
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
app.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from PIL import Image
|
| 2 |
+
import tensorflow as tf
|
| 3 |
+
import streamlit as st
|
| 4 |
+
from deep_learning_pipeline import PredictionPipeline
|
| 5 |
+
|
| 6 |
+
st.title('Malaria Infected Cell Detection using X-ray Images')
|
| 7 |
+
st.write('This Project is built using CNN (Convolutional Neural Networks) Transfer Learning model that helps to predict whether the given X-ray image of the cell is Malaria Infected or Healthy!!')
|
| 8 |
+
|
| 9 |
+
st.write('')
|
| 10 |
+
st.write('')
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
uploaded_file = st.file_uploader("Upload an image", type=["png", "jpg", "jpeg"])
|
| 14 |
+
|
| 15 |
+
if uploaded_file is not None:
|
| 16 |
+
# Process the uploaded image here
|
| 17 |
+
with st.container():
|
| 18 |
+
col1, col2 = st.columns([3, 2])
|
| 19 |
+
col1.image(uploaded_file, caption="Uploaded Image", use_column_width=True)
|
| 20 |
+
|
| 21 |
+
if st.button('Predict!!'):
|
| 22 |
+
pipeline = PredictionPipeline()
|
| 23 |
+
resnet152v2_y_pred, resnet152v2_y_probs = pipeline.predict(input_img=uploaded_file)
|
| 24 |
+
col2.balloons()
|
| 25 |
+
if resnet152v2_y_pred[0][0] == 1:
|
| 26 |
+
col2.subheader('ResNET 152V2 model: ')
|
| 27 |
+
col2.success(f'{pipeline.CLASS_NAMES[1]}')
|
| 28 |
+
r_acc = '{:.2f}'.format(100*(resnet152v2_y_probs[0][0]))
|
| 29 |
+
col2.success(f'Accuracy: {r_acc}%')
|
| 30 |
+
elif resnet152v2_y_pred[0][0] == 0:
|
| 31 |
+
col2.subheader('ResNET 152V2 model: ')
|
| 32 |
+
col2.success(f'{pipeline.CLASS_NAMES[0]}')
|
| 33 |
+
r_acc = '{:.2f}'.format(100*(1-resnet152v2_y_probs[0][0]))
|
| 34 |
+
col2.success(f'Accuracy: {r_acc}%')
|
| 35 |
+
|
| 36 |
+
elif resnet152v2_y_pred[[0]] == -1:
|
| 37 |
+
col2.error('Error!! Model needs shape (224, 224, 3), but your image is of shape (224, 224,4)')
|
deep_learning_pipeline.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import tensorflow as tf
|
| 2 |
+
from tensorflow import keras
|
| 3 |
+
from keras.models import load_model
|
| 4 |
+
from PIL import Image
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class PredictionPipeline():
|
| 8 |
+
def __init__(self) -> None:
|
| 9 |
+
self.CLASS_NAMES = ['Malaria Infected cell', 'Healthy Cell']
|
| 10 |
+
self.IMG_SIZE = 224
|
| 11 |
+
|
| 12 |
+
def predict(self, input_img):
|
| 13 |
+
# Loading ResNet152v2 model
|
| 14 |
+
resnet_152v2_model = load_model('model_resnet152v2.h5')
|
| 15 |
+
# Image Preprocessing
|
| 16 |
+
image = Image.open(input_img)
|
| 17 |
+
image = tf.cast(image, dtype=tf.float32)
|
| 18 |
+
image = image / 255.0
|
| 19 |
+
input_tensor = tf.expand_dims(tf.image.resize(image, [self.IMG_SIZE, self.IMG_SIZE]), axis=0)
|
| 20 |
+
# Making Predictions
|
| 21 |
+
try:
|
| 22 |
+
resnet_152v2_y_probs = resnet_152v2_model.predict(input_tensor)
|
| 23 |
+
except ValueError as err:
|
| 24 |
+
return [[-1]], err, err, err
|
| 25 |
+
else:
|
| 26 |
+
return tf.round(resnet_152v2_y_probs), resnet_152v2_y_probs
|
model_resnet152v2.h5
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:2450ac6a99a8355c4d93b8334a88d9ee46ea260572f771a70115c00a5cd59e58
|
| 3 |
+
size 542988016
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
tensorflow==2.13.0
|
| 2 |
+
Pillow==10.1.0
|
| 3 |
+
streamlit
|