File size: 4,032 Bytes
bbecad4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
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)












# st.sidebar.title("Choose the Model:")
# option = st.sidebar.selectbox("Select model",["model1","model2"])


# if option == "model1":
#     st.header("Model 1")
#     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)
#         img = cv2.resize(img,(250,250))
#         img_input = img.reshape((1,250,250,3))
#         y_pred = model1.predict(img_input).argmax(axis=1)
        
#         if y_pred[0] == 0:
#             st.write("Target: glioma_tumor")
#         elif y_pred[0] == 1:
#             st.write("Target: meningioma_tumor")
#         elif y_pred[0] == 2:
#             st.write("Target: no_tumor")
#         else:
#             st.write("Target: pituitary_tumor")

#     else:
#         st.warning("Not Entered image")

# if option == "model2":
#     st.header("Model 2")
#     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)
#         img = cv2.resize(img,(250,250))
#         img_input = img.reshape((1,250,250,3))
#         y_pred = model2.predict(img_input).argmax(axis=1)
        
#         if y_pred[0] == 0:
#             st.write("Target: glioma_tumor")
#         elif y_pred[0] == 1:
#             st.write("Target: meningioma_tumor")
#         elif y_pred[0] == 2:
#             st.write("Target: no_tumor")
#         else:
#             st.write("Target: pituitary_tumor")

#     else:
#         st.warning("Not Entered image")