File size: 2,202 Bytes
f0cc107
f493bbd
256fc75
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f493bbd
9bca0e0
 
65842e9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73

import streamlit as st
import tensorflow as tf
from tensorflow import keras
import cv2


st.title(":brain: Brain Tumor Detection (MRI)")



vggnet_19= keras.models.load_model("CNN_MODEL_0_9687.h5")
vggnet_16 = keras.models.load_model("CNN_MODEL_0_96414.h5")
resnet_152 = keras.models.load_model("CNN_MODEL_0_9794.h5")
mobilenet_v3= keras.models.load_model("CNN_MODEL_0_9771.h5")


def check_accuracy(model,img_input):
    y_pred = model.predict(img_input).argmax(axis=1)
    prediction = model.predict(img_input)
    if y_pred[0] == 0:
        return "Target: glioma_tumor",prediction.max()
    elif y_pred[0] == 1:
        return "Target: meningioma_tumor",prediction.max()
    elif y_pred[0] == 2:
        return "Target: no_tumor",prediction.max()
    else:
        return "Target: pituitary_tumor",prediction.max()



with st.container():
    file = st.file_uploader("Upload the MRI Image")
    if file is not None:
        print(file)
        save_image_path = "./upload_images/"+file.name
        with open(save_image_path,"wb") as f:
            f.write(file.getbuffer())
        img = cv2.imread(save_image_path)

col1,col2 = st.columns(2)
with st.container():
    if file is not None:
        with col1:
            st.write("Original Image:")
            st.image(file)
        with col2:
            st.write("Processed Image:")
            st.image(cv2.resize(img,(224,224)))
    else:
        st.error("First upload image")

with st.container():
    if file is not None:
        img = cv2.resize(img,(224,224))
        img_input = img.reshape((1,224,224,3))
        vgg19,v19 = check_accuracy(vggnet_19,img_input)
        vgg16,v16 = check_accuracy(vggnet_16,img_input)
        resnet,r152 = check_accuracy(resnet_152,img_input)
        mobilenet,mv3 = check_accuracy(mobilenet_v3,img_input)
        st.subheader(vgg19+" for"+ " VGGNET-19")
        st.write("accuracy of the image",v19)
        st.subheader(vgg16+" for"+ " VGGNET-16")
        st.write("accuracy of the image",v16)
        st.subheader(resnet+" for"+ " RESNET-152")
        st.write("accuracy of the image",r152)
        st.subheader(mobilenet+" for"+ " MOBILENET-V3")
        st.write("accuracy of the image",mv3)