|
|
|
import streamlit as st |
|
from tensorflow.keras.models import load_model |
|
from PIL import Image |
|
import numpy as np |
|
import tensorflow as tf |
|
|
|
|
|
model1 = load_model('Model_From_VGG16.h5') |
|
model2 = load_model('Model_basic_From_Scratch.h5') |
|
|
|
|
|
def predict_model1(image): |
|
|
|
img = np.array(image.convert('RGB').resize((64, 64))) / 255.0 |
|
img = np.expand_dims(img, axis=0) |
|
|
|
|
|
prediction = model1.predict(img) |
|
return prediction |
|
|
|
|
|
def predict_model2(image): |
|
|
|
img = np.array(image.convert('RGB').resize((128, 128))) / 255.0 |
|
img = np.expand_dims(img, axis=0) |
|
|
|
|
|
prediction = model2.predict(img) |
|
return prediction |
|
|
|
|
|
def app(): |
|
st.title('Malaria Parasite Presence Detector Using Not One But Two Models') |
|
st.write('Upload an image and see the predictions of two CNN models!') |
|
|
|
|
|
uploaded_file = st.file_uploader("Upload Magnified Blood Samples Only!", type=["jpg", "jpeg", "png"]) |
|
|
|
|
|
if uploaded_file is not None: |
|
|
|
image = Image.open(uploaded_file) |
|
|
|
|
|
st.image(image, caption='Uploaded Image', use_column_width=True) |
|
|
|
|
|
prediction1 = predict_model1(image) |
|
|
|
|
|
prediction2 = predict_model2(image) |
|
|
|
|
|
st.subheader('Model 1 Prediction - Transfer Learning_VGG16') |
|
if np.argmax(prediction1) == 0: |
|
st.write("Malaria Parasite Not Present in the Blood sample") |
|
else: |
|
st.write("Malaria Parasite Present in the Blood sample") |
|
|
|
st.subheader('Model 2 Prediction - Built from Scratch') |
|
if np.round(prediction2) == 1: |
|
st.write("Malaria Parasite Not Present in the Blood sample") |
|
else: |
|
st.write("Malaria Parasite Present in the Blood sample") |
|
|
|
|
|
if __name__ == '__main__': |
|
app() |