-
Notifications
You must be signed in to change notification settings - Fork 0
/
IDC_Detector.py
70 lines (55 loc) · 2.62 KB
/
IDC_Detector.py
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
import numpy as np
import streamlit as st
import tensorflow as tf
from keras.models import load_model
from streamlit.logger import get_logger
st.set_page_config(page_title="Invasive Ductal Carcinoma", page_icon="🕵️♀️")
LOGGER = get_logger(__name__)
@st.cache(allow_output_mutation=True)
def loadIDCModel():
model_idc = load_model('models/IDC_model.h5', compile=True)
model_idc.summary()
return model_idc
st.markdown('<h1 style="text-align: center;">Identificar câncer de mama</h1>', unsafe_allow_html=True)
st.subheader('Identificação de IDC e Metastases por imagens, usando rede neural, e identificação por variáveis')
c = st.container()
c.markdown("# Identificar IDC 🕵️♀️")
### load file
uploaded_file = c.file_uploader("Escolha uma imagem", type=["png", "jpg", "jpeg"])
if uploaded_file is not None:
# transform image to numpy array
image_uploaded = tf.keras.preprocessing.image.load_img(uploaded_file, target_size=(50,50),
grayscale = False, interpolation = 'nearest', color_mode = 'rgb', keep_aspect_ratio = False)
# image_uploaded = tf.keras.applications.mobilenet.preprocess_input(image_uploaded)
input_arr = tf.keras.preprocessing.image.img_to_array(image_uploaded)
imput_arr = np.expand_dims(input_arr, axis=0)
imput_arr /= 255
c.image(image_uploaded, channels="RGB")
Genrate_pred = c.button("Gerar Predição")
if Genrate_pred:
model = loadIDCModel()
probability_model = tf.keras.Sequential([model, tf.keras.layers.Softmax()])
prediction = probability_model.predict(input_arr.reshape(1,50,50,3))
dict_pred = {0: 'Benigno/Normal', 1: 'Maligno'}
result = dict_pred[np.argmax(prediction)]
value = 0
if result == 'Benigno/Normal':
value = str(((prediction[0][0])*100).round(2)) + '%'
else:
value = str(((prediction[0][1])*100).round(2)) + '%'
c.metric('Predição', result, delta=value, delta_color='normal')
def IDC_Detector():
st.sidebar.markdown("# Análise de imagens 🕵️♀️")
def Metastase_Detector():
st.markdown("# Identificar Metástase 🔬")
st.sidebar.markdown("# Análise de imagens 🔬")
def Variaveis_Detector():
st.markdown("# Identificar Câncer de mama 🧬")
st.sidebar.markdown("# Análise de variáveis 🧬")
page_names_to_funcs = {
"Identificar IDC": IDC_Detector,
"Identificar Metastase": Metastase_Detector,
"Identificar Câncer de mama": Variaveis_Detector,
}
selected_page = st.sidebar.selectbox("Selecione a Página", page_names_to_funcs.keys())
page_names_to_funcs[selected_page]()