Spaces:
Sleeping
Sleeping
Deevyankar
commited on
Commit
•
aabb384
1
Parent(s):
39eeca1
Upload 8 files
Browse files- EBNfold3.pth +3 -0
- ENB0ADvsCNbest_metric_model_classification3d_dict.pth +3 -0
- F3DENSENET264ADvsCNbest_metric_model_classification3d_dict.pth +3 -0
- MNI152_T1_1mm_brain.nii.gz +3 -0
- README (1).md +13 -0
- latest_app1.py +448 -0
- requirements (1).txt +26 -0
- unilogo.png +0 -0
EBNfold3.pth
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:c2f9e86c8f304b9a2c19f8eeee7f6099b3135c57e585a6102e679523d41f70c5
|
3 |
+
size 19057329
|
ENB0ADvsCNbest_metric_model_classification3d_dict.pth
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:4d061ff8c05174f1a15507bcbe3861f957b235da4063294174543deb43b942e7
|
3 |
+
size 19057329
|
F3DENSENET264ADvsCNbest_metric_model_classification3d_dict.pth
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:e2e74940e3614ede3bf765084b5c4a82ba3398250f36a039246452c623f38931
|
3 |
+
size 163217954
|
MNI152_T1_1mm_brain.nii.gz
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:32d5be33460f995a5d305507053c8862c823d9ca6bfb543381308df14590f212
|
3 |
+
size 3219212
|
README (1).md
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: Deep-AD
|
3 |
+
emoji: 🧠
|
4 |
+
colorFrom: red
|
5 |
+
colorTo: blue
|
6 |
+
sdk: streamlit
|
7 |
+
sdk_version: 1.10.0
|
8 |
+
app_file: app.py
|
9 |
+
python_version: 3.8.15
|
10 |
+
pinned: false
|
11 |
+
---
|
12 |
+
|
13 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
latest_app1.py
ADDED
@@ -0,0 +1,448 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import ants
|
3 |
+
import monai
|
4 |
+
import torch
|
5 |
+
import shutil
|
6 |
+
import numpy as np
|
7 |
+
import pandas as pd
|
8 |
+
import altair as alt
|
9 |
+
import nibabel as nib
|
10 |
+
import streamlit as st
|
11 |
+
from random import randint
|
12 |
+
from itertools import chain
|
13 |
+
import antspynet as antspynet
|
14 |
+
from torch.utils.data import DataLoader
|
15 |
+
from monai.transforms import Compose, LoadImaged
|
16 |
+
from monai.networks.nets.efficientnet import EfficientNetBN
|
17 |
+
|
18 |
+
st.set_option('deprecation.showPyplotGlobalUse', False)
|
19 |
+
np.random.seed(0)
|
20 |
+
|
21 |
+
template = ants.image_read('MNI152_T1_1mm_brain.nii.gz')
|
22 |
+
|
23 |
+
|
24 |
+
def pre_process(image):
|
25 |
+
with st.spinner('Reading the image...'):
|
26 |
+
y = ants.image_read(image)
|
27 |
+
with st.spinner('Bias field correction ongoing...'):
|
28 |
+
y = ants.utils.n4_bias_field_correction(y)
|
29 |
+
with st.spinner('Denoising the image...'):
|
30 |
+
yn = y + np.random.randn(*y.shape).astype('float32')*5
|
31 |
+
y = ants.denoise_image(yn, ants.get_mask(y))
|
32 |
+
with st.spinner('brain_extraction fn. running...'):
|
33 |
+
x = antspynet.utilities.brain_extraction(
|
34 |
+
y, modality='t1', antsxnet_cache_directory=None, verbose=True)
|
35 |
+
y = y*x
|
36 |
+
with st.spinner('Registering from template..'):
|
37 |
+
y1 = ants.registration(fixed=template, moving=y,
|
38 |
+
type_of_transform='AffineFast')
|
39 |
+
with st.spinner('Applying transforms...'):
|
40 |
+
y = ants.apply_transforms(
|
41 |
+
fixed=template, moving=y, transformlist=y1['fwdtransforms'])
|
42 |
+
st.success('Successfully Preprocessed the Image !')
|
43 |
+
return y
|
44 |
+
|
45 |
+
|
46 |
+
col1, col2, col3 = st.columns(3)
|
47 |
+
|
48 |
+
with col1:
|
49 |
+
st.write(' ')
|
50 |
+
|
51 |
+
with col2:
|
52 |
+
st.image("unilogo.png")
|
53 |
+
|
54 |
+
with col3:
|
55 |
+
st.write(' ')
|
56 |
+
|
57 |
+
st.markdown("<h1 style='text-align: center; color: grey;'>Deep-AD: Deep Learning Model for Early Detection of Alzheimer’s</h1>", unsafe_allow_html=True)
|
58 |
+
st.markdown("<h6 style='text-align: center; color: grey;'>Developed by: Deevyankar Agarwal</h6>",
|
59 |
+
unsafe_allow_html=True)
|
60 |
+
st.markdown("<h6 style='text-align: center; color: grey;'> Part Time Ph.D. Student, UVA, Spain</h6>",
|
61 |
+
unsafe_allow_html=True)
|
62 |
+
st.write('**Description**: Users can upload T1-W MRIs either in NifTI or DICOM format. After preprocessing (N4 bias field correction, noise removal, brain extraction, and registration in the MNI-152 template), the model will classify MRI scans into one of three groups.')
|
63 |
+
|
64 |
+
st.markdown('- AD : Alzheimer’s')
|
65 |
+
st.markdown('- CN : Cognitively Normal')
|
66 |
+
st.markdown('- SMCI : stable MCI')
|
67 |
+
|
68 |
+
st.write('This Application is based on ensemble learning. The output of multiclassification task AD vs. sMCI vs. CN will be validated further by binary classification models AD vs. CN and sMCI vs. AD implemented by end-to-end learning and 3D transfer learning, respectively. It will provide an extra layer of verification to make robust decisions.')
|
69 |
+
st.markdown('''<br>''', unsafe_allow_html=True)
|
70 |
+
|
71 |
+
element1 = st.write("""
|
72 |
+
# MRI Classification :brain:
|
73 |
+
"""
|
74 |
+
)
|
75 |
+
|
76 |
+
if 'key' not in st.session_state:
|
77 |
+
st.session_state.key = str(randint(1000, 100000000))
|
78 |
+
file_upload = st.file_uploader("Upload the MRI scan (either a single NIfTI file or a folder containing multiple DICOM files)", type=[
|
79 |
+
"nii", "gz", "dcm"], accept_multiple_files=True, key=st.session_state.key)
|
80 |
+
st.set_option('deprecation.showfileUploaderEncoding', False)
|
81 |
+
|
82 |
+
|
83 |
+
if file_upload == []:
|
84 |
+
st.text("No file uploaded !")
|
85 |
+
|
86 |
+
st.text('Note : Please clear existing files before uploading new files')
|
87 |
+
if st.button('Clear Uploaded File(s)', help='Please clear existing files before uploading new files') and 'key' in st.session_state.keys():
|
88 |
+
st.session_state.pop('key')
|
89 |
+
st.experimental_rerun()
|
90 |
+
|
91 |
+
st.write("⚠️ [**Feedback form**](https://forms.gle/xuScGN6Cmf69bsUE9) ⚠️ ")
|
92 |
+
|
93 |
+
|
94 |
+
if len(file_upload) == 1:
|
95 |
+
|
96 |
+
for file in file_upload:
|
97 |
+
file.name = file.name
|
98 |
+
with open(file.name, "wb") as f:
|
99 |
+
f.write(file.getbuffer())
|
100 |
+
|
101 |
+
saved_path = f"{file.name}"
|
102 |
+
|
103 |
+
display_image = ants.image_read(saved_path)
|
104 |
+
element2 = st.pyplot(ants.plot(display_image))
|
105 |
+
|
106 |
+
processed_image = pre_process(saved_path)
|
107 |
+
a = processed_image.to_nibabel()
|
108 |
+
saved_preprocessed_path = 'input_image'
|
109 |
+
nib.save(a, saved_preprocessed_path)
|
110 |
+
element3 = st.text("Preprocessed Image")
|
111 |
+
element4 = st.pyplot(ants.plot(f"{saved_preprocessed_path}.nii", cmap="seismic"))
|
112 |
+
|
113 |
+
transformsv = Compose(
|
114 |
+
[
|
115 |
+
LoadImaged(keys=["img"])
|
116 |
+
]
|
117 |
+
)
|
118 |
+
|
119 |
+
test_files = [{"img": f"{saved_preprocessed_path}.nii", "label": "NA"}]
|
120 |
+
test_ds = monai.data.Dataset(data=test_files, transform=transformsv)
|
121 |
+
test_loader = DataLoader(test_ds, batch_size=1,
|
122 |
+
pin_memory=torch.cuda.is_available())
|
123 |
+
|
124 |
+
for test_data in test_loader:
|
125 |
+
test_images, test_labels = test_data["img"], test_data["label"]
|
126 |
+
|
127 |
+
with st.spinner('Performing Inference...'):
|
128 |
+
model = EfficientNetBN(
|
129 |
+
"efficientnet-b0", spatial_dims=3, in_channels=1, num_classes=3)
|
130 |
+
model.load_state_dict(torch.load(
|
131 |
+
'MCEBNfold1.pth', map_location='cpu'))
|
132 |
+
model.eval()
|
133 |
+
prediction = model(test_images.unsqueeze(1))
|
134 |
+
pred = prediction.argmax(dim=1).item()
|
135 |
+
class_names = ["SMCI", "AD", "CN"]
|
136 |
+
predicted_label = class_names[pred]
|
137 |
+
|
138 |
+
graph_input = list(chain.from_iterable(prediction.tolist()))
|
139 |
+
"Plot depicting Class Probabilities"
|
140 |
+
source = pd.DataFrame({
|
141 |
+
'Model output': graph_input,
|
142 |
+
'class': ["SMCI", "AD", "CN"]
|
143 |
+
})
|
144 |
+
|
145 |
+
bar_chart = alt.Chart(source).mark_bar().encode(
|
146 |
+
y='Model output:Q',
|
147 |
+
x='class:O',
|
148 |
+
)
|
149 |
+
|
150 |
+
element5 = st.altair_chart(bar_chart, use_container_width=True)
|
151 |
+
|
152 |
+
element6 = st.write(
|
153 |
+
f"The MRI Scan belong to the class **{predicted_label}**")
|
154 |
+
|
155 |
+
|
156 |
+
if pred == 0:
|
157 |
+
with st.spinner('Please wait...verifying the model output with another model'):
|
158 |
+
model_verify = monai.networks.nets.DenseNet264(spatial_dims=3, in_channels=1, out_channels=2)
|
159 |
+
model_verify.load_state_dict(torch.load(
|
160 |
+
'F3DENSENET264ADvsCNbest_metric_model_classification3d_dict.pth', map_location='cpu'))
|
161 |
+
model_verify.eval()
|
162 |
+
prediction_verify = model_verify(test_images.unsqueeze(1))
|
163 |
+
pred_verify = prediction_verify.argmax(dim=1).item()
|
164 |
+
class_names_verify = ["CN", "AD"]
|
165 |
+
predicted_label_verify = class_names_verify[pred_verify]
|
166 |
+
|
167 |
+
if pred_verify == 0:
|
168 |
+
|
169 |
+
if predicted_label_verify == predicted_label:
|
170 |
+
st.write(
|
171 |
+
f"Succesfully Verified the result, both models classified the scan as **{predicted_label_verify}**")
|
172 |
+
else:
|
173 |
+
st.write(
|
174 |
+
f"Verifying gave a different result ! **First model predicted as {predicted_label}, other predicted {predicted_label_verify}**")
|
175 |
+
|
176 |
+
if pred_verify == 1 :
|
177 |
+
|
178 |
+
model_verify = EfficientNetBN(
|
179 |
+
"efficientnet-b0", spatial_dims=3, in_channels=1, num_classes=2)
|
180 |
+
model_verify.load_state_dict(torch.load(
|
181 |
+
'EBNfold3.pth', map_location='cpu'))
|
182 |
+
model_verify.eval()
|
183 |
+
prediction_verify = model_verify(test_images.unsqueeze(1))
|
184 |
+
pred_verify = prediction_verify.argmax(dim=1).item()
|
185 |
+
class_names_verify = ["SMCI", "AD"]
|
186 |
+
predicted_label_verify = class_names_verify[pred_verify]
|
187 |
+
|
188 |
+
if predicted_label_verify == predicted_label:
|
189 |
+
st.write(
|
190 |
+
f"Succesfully Verified the result, both models classified the scan as **{predicted_label_verify}**")
|
191 |
+
else:
|
192 |
+
st.write(
|
193 |
+
f"Verifying gave a different result ! **First model predicted as {predicted_label}, other predicted {predicted_label_verify}**")
|
194 |
+
|
195 |
+
st.write("Kindly consider output of the second model to be more accurate")
|
196 |
+
|
197 |
+
|
198 |
+
|
199 |
+
if pred == 1:
|
200 |
+
with st.spinner('Please wait...verifying the model output with another model'):
|
201 |
+
model_verify = EfficientNetBN(
|
202 |
+
"efficientnet-b0", spatial_dims=3, in_channels=1, num_classes=2)
|
203 |
+
model_verify.load_state_dict(torch.load(
|
204 |
+
'EBNfold3.pth', map_location='cpu'))
|
205 |
+
model_verify.eval()
|
206 |
+
prediction_verify = model_verify(test_images.unsqueeze(1))
|
207 |
+
pred_verify = prediction_verify.argmax(dim=1).item()
|
208 |
+
class_names_verify = ["SMCI", "AD"]
|
209 |
+
predicted_label_verify = class_names_verify[pred_verify]
|
210 |
+
|
211 |
+
if predicted_label_verify == predicted_label:
|
212 |
+
st.write(
|
213 |
+
f"Succesfully Verified the result, both models classified the scan as **{predicted_label_verify}**")
|
214 |
+
else:
|
215 |
+
st.write(
|
216 |
+
f"Verifying gave a different result ! **First model predicted as {predicted_label}, other predicted {predicted_label_verify}**")
|
217 |
+
|
218 |
+
st.write("Kindly consider output of the second model to be more accurate")
|
219 |
+
|
220 |
+
if pred == 2:
|
221 |
+
with st.spinner('Please wait...verifying the model output with another model'):
|
222 |
+
model_verify = EfficientNetBN(
|
223 |
+
"efficientnet-b0", spatial_dims=3, in_channels=1, num_classes=2)
|
224 |
+
model_verify.load_state_dict(torch.load(
|
225 |
+
'ENB0ADvsCNbest_metric_model_classification3d_dict.pth', map_location='cpu'))
|
226 |
+
model_verify.eval()
|
227 |
+
prediction_verify = model_verify(test_images.unsqueeze(1))
|
228 |
+
pred_verify = prediction_verify.argmax(dim=1).item()
|
229 |
+
class_names_verify = ["CN", "AD"]
|
230 |
+
predicted_label_verify = class_names_verify[pred_verify]
|
231 |
+
|
232 |
+
if predicted_label_verify == predicted_label:
|
233 |
+
st.write(
|
234 |
+
f"Succesfully Verified the result, both models classified the scan as **{predicted_label_verify}**")
|
235 |
+
else:
|
236 |
+
st.write(
|
237 |
+
f"Verifying gave a different result ! **First model predicted as {predicted_label}, other predicted {predicted_label_verify}**")
|
238 |
+
|
239 |
+
st.write("Kindly consider output of the second model to be more accurate")
|
240 |
+
|
241 |
+
|
242 |
+
graph_input_1 = list(chain.from_iterable(prediction_verify.tolist()))
|
243 |
+
|
244 |
+
"Plot depicting verifying model outputs"
|
245 |
+
source_1 = pd.DataFrame({
|
246 |
+
'Model output': graph_input_1,
|
247 |
+
'class': class_names_verify
|
248 |
+
})
|
249 |
+
|
250 |
+
bar_chart_1 = alt.Chart(source_1).mark_bar().encode(
|
251 |
+
y='Model output:Q',
|
252 |
+
x='class:O',
|
253 |
+
)
|
254 |
+
|
255 |
+
st.altair_chart(bar_chart_1, use_container_width=True)
|
256 |
+
|
257 |
+
|
258 |
+
if len(file_upload) > 1:
|
259 |
+
|
260 |
+
if os.path.exists('tmp') == True:
|
261 |
+
shutil.rmtree('tmp')
|
262 |
+
os.makedirs('tmp')
|
263 |
+
|
264 |
+
for file in file_upload:
|
265 |
+
file.name = file.name
|
266 |
+
with open(file.name, "wb") as f:
|
267 |
+
f.write(file.getbuffer())
|
268 |
+
shutil.copy(file.name, 'tmp')
|
269 |
+
|
270 |
+
display_image = st.empty()
|
271 |
+
display_image = ants.core.ants_image_io.dicom_read('tmp')
|
272 |
+
element2 = st.pyplot(ants.plot(display_image))
|
273 |
+
|
274 |
+
b = display_image.to_nibabel()
|
275 |
+
saved_path = 'uploaded_image'
|
276 |
+
nib.save(b, saved_path)
|
277 |
+
|
278 |
+
processed_image = pre_process(f"{saved_path}.nii")
|
279 |
+
a = processed_image.to_nibabel()
|
280 |
+
saved_preprocessed_path = 'input_image'
|
281 |
+
nib.save(a, saved_preprocessed_path)
|
282 |
+
element3 = st.text("Preprocessed Image")
|
283 |
+
element4 = st.pyplot(ants.plot(f"{saved_preprocessed_path}.nii", cmap="seismic"))
|
284 |
+
|
285 |
+
transformsv = Compose(
|
286 |
+
[
|
287 |
+
LoadImaged(keys=["img"])
|
288 |
+
]
|
289 |
+
)
|
290 |
+
|
291 |
+
test_files = [{"img": f"{saved_preprocessed_path}.nii", "label": 1}]
|
292 |
+
test_ds = monai.data.Dataset(data=test_files, transform=transformsv)
|
293 |
+
test_loader = DataLoader(test_ds, batch_size=1,
|
294 |
+
pin_memory=torch.cuda.is_available())
|
295 |
+
|
296 |
+
for test_data in test_loader:
|
297 |
+
test_images, test_labels = test_data["img"], test_data["label"]
|
298 |
+
with st.spinner('Performing Inference...'):
|
299 |
+
model = EfficientNetBN(
|
300 |
+
"efficientnet-b0", spatial_dims=3, in_channels=1, num_classes=3)
|
301 |
+
model.load_state_dict(torch.load(
|
302 |
+
'MCEBNfold1.pth', map_location='cpu'))
|
303 |
+
model.eval()
|
304 |
+
prediction = model(test_images.unsqueeze(1))
|
305 |
+
pred = prediction.argmax(dim=1).item()
|
306 |
+
class_names = ["SMCI", "AD", "CN"]
|
307 |
+
predicted_label = class_names[pred]
|
308 |
+
|
309 |
+
graph_input = list(chain.from_iterable(prediction.tolist()))
|
310 |
+
"Plot depicting Class Probabilities"
|
311 |
+
source = pd.DataFrame({
|
312 |
+
'Model output': graph_input,
|
313 |
+
'class': ["SMCI", "AD", "CN"]
|
314 |
+
})
|
315 |
+
|
316 |
+
bar_chart = alt.Chart(source).mark_bar().encode(
|
317 |
+
y='Model output:Q',
|
318 |
+
x='class:O',
|
319 |
+
)
|
320 |
+
|
321 |
+
element5 = st.altair_chart(bar_chart, use_container_width=True)
|
322 |
+
|
323 |
+
element6 = st.write(
|
324 |
+
f"The MRI Scan belong to the class **{predicted_label}**")
|
325 |
+
|
326 |
+
|
327 |
+
|
328 |
+
if pred == 0:
|
329 |
+
with st.spinner('Please wait...verifying the model output with another model'):
|
330 |
+
model_verify = monai.networks.nets.DenseNet264(spatial_dims=3, in_channels=1, out_channels=2)
|
331 |
+
model_verify.load_state_dict(torch.load(
|
332 |
+
'F3DENSENET264ADvsCNbest_metric_model_classification3d_dict.pth', map_location='cpu'))
|
333 |
+
model_verify.eval()
|
334 |
+
prediction_verify = model_verify(test_images.unsqueeze(1))
|
335 |
+
pred_verify = prediction_verify.argmax(dim=1).item()
|
336 |
+
class_names_verify = ["CN", "AD"]
|
337 |
+
predicted_label_verify = class_names_verify[pred_verify]
|
338 |
+
|
339 |
+
if pred_verify == 0:
|
340 |
+
|
341 |
+
if predicted_label_verify == predicted_label:
|
342 |
+
st.write(
|
343 |
+
f"Succesfully Verified the result, both models classified the scan as **{predicted_label_verify}**")
|
344 |
+
else:
|
345 |
+
st.write(
|
346 |
+
f"Verifying gave a different result ! **First model predicted as {predicted_label}, other predicted {predicted_label_verify}**")
|
347 |
+
|
348 |
+
if pred_verify == 1 :
|
349 |
+
|
350 |
+
model_verify = EfficientNetBN(
|
351 |
+
"efficientnet-b0", spatial_dims=3, in_channels=1, num_classes=2)
|
352 |
+
model_verify.load_state_dict(torch.load(
|
353 |
+
'EBNfold3.pth', map_location='cpu'))
|
354 |
+
model_verify.eval()
|
355 |
+
prediction_verify = model_verify(test_images.unsqueeze(1))
|
356 |
+
pred_verify = prediction_verify.argmax(dim=1).item()
|
357 |
+
class_names_verify = ["SMCI", "AD"]
|
358 |
+
predicted_label_verify = class_names_verify[pred_verify]
|
359 |
+
|
360 |
+
if predicted_label_verify == predicted_label:
|
361 |
+
st.write(
|
362 |
+
f"Succesfully Verified the result, both models classified the scan as **{predicted_label_verify}**")
|
363 |
+
else:
|
364 |
+
st.write(
|
365 |
+
f"Verifying gave a different result ! **First model predicted as {predicted_label}, other predicted {predicted_label_verify}**")
|
366 |
+
|
367 |
+
st.write("Kindly consider output of the second model to be more accurate")
|
368 |
+
|
369 |
+
|
370 |
+
if pred == 1:
|
371 |
+
with st.spinner('Please wait...verifying the model output with another model'):
|
372 |
+
model_verify = EfficientNetBN(
|
373 |
+
"efficientnet-b0", spatial_dims=3, in_channels=1, num_classes=2)
|
374 |
+
model_verify.load_state_dict(torch.load(
|
375 |
+
'EBNfold3.pth', map_location='cpu'))
|
376 |
+
model_verify.eval()
|
377 |
+
prediction_verify = model_verify(test_images.unsqueeze(1))
|
378 |
+
pred_verify = prediction_verify.argmax(dim=1).item()
|
379 |
+
class_names_verify = ["SMCI", "AD"]
|
380 |
+
predicted_label_verify = class_names_verify[pred_verify]
|
381 |
+
|
382 |
+
if predicted_label_verify == predicted_label:
|
383 |
+
st.write(
|
384 |
+
f"Succesfully Verified the result, both models classified the scan as **{predicted_label_verify}**")
|
385 |
+
else:
|
386 |
+
st.write(
|
387 |
+
f"Verifying gave a different result ! **First model predicted as {predicted_label}, other predicted {predicted_label_verify}**")
|
388 |
+
|
389 |
+
st.write("Kindly consider output of the second model to be more accurate")
|
390 |
+
|
391 |
+
if pred == 2:
|
392 |
+
with st.spinner('Please wait...verifying the model output with another model'):
|
393 |
+
model_verify = monai.networks.nets.DenseNet264(spatial_dims=3, in_channels=1, out_channels=2)
|
394 |
+
model_verify.load_state_dict(torch.load(
|
395 |
+
'F3DENSENET264ADvsCNbest_metric_model_classification3d_dict.pth', map_location='cpu'))
|
396 |
+
model_verify.eval()
|
397 |
+
prediction_verify = model_verify(test_images.unsqueeze(1))
|
398 |
+
pred_verify = prediction_verify.argmax(dim=1).item()
|
399 |
+
class_names_verify = ["CN", "AD"]
|
400 |
+
predicted_label_verify = class_names_verify[pred_verify]
|
401 |
+
|
402 |
+
if predicted_label_verify == predicted_label:
|
403 |
+
st.write(
|
404 |
+
f"Succesfully Verified the result, both models classified the scan as **{predicted_label_verify}**")
|
405 |
+
else:
|
406 |
+
st.write(
|
407 |
+
f"Verifying gave a different result ! **First model predicted as {predicted_label}, other predicted {predicted_label_verify}**")
|
408 |
+
|
409 |
+
st.write("Kindly consider output of the second model to be more accurate")
|
410 |
+
|
411 |
+
|
412 |
+
|
413 |
+
graph_input_1 = list(chain.from_iterable(prediction_verify.tolist()))
|
414 |
+
|
415 |
+
"Plot depicting verifying model outputs"
|
416 |
+
source_1 = pd.DataFrame({
|
417 |
+
'Model output': graph_input_1,
|
418 |
+
'class': class_names_verify
|
419 |
+
})
|
420 |
+
|
421 |
+
bar_chart_1 = alt.Chart(source_1).mark_bar().encode(
|
422 |
+
y='Model output:Q',
|
423 |
+
x='class:O',
|
424 |
+
)
|
425 |
+
|
426 |
+
st.altair_chart(bar_chart_1, use_container_width=True)
|
427 |
+
|
428 |
+
|
429 |
+
st.markdown('''<br><br>''', unsafe_allow_html=True)
|
430 |
+
st.markdown('''#### Publications :book:''', unsafe_allow_html=True)
|
431 |
+
|
432 |
+
st.markdown("""1. [Transfer Learning for Alzheimer’s Disease through Neuroimaging Biomarkers: A Systematic Review](https://www.mdpi.com/1424-8220/21/21/7259 ) \n
|
433 |
+
<small>Q1 Sensors</small> <br><br>
|
434 |
+
|
435 |
+
2. [End-to-End Deep Learning Architectures Using 3D Neuroimaging Biomarkers for Early Alzheimer’s Diagnosis](https://www.mdpi.com/2227-7390/10/15/2575) \n
|
436 |
+
<small>Q2 mathematics</small> <br><br>
|
437 |
+
<br>""", unsafe_allow_html=True)
|
438 |
+
|
439 |
+
st.markdown('''#### Contact details :mailbox:''', unsafe_allow_html=True)
|
440 |
+
|
441 |
+
st.markdown('''
|
442 |
+
<b>Group :busts_in_silhouette: </b>: http://www.sigte.tel.uva.es/index.php/en/homepage/
|
443 |
+
<small>The eHealth and Telemedicine Group (GTe) of the University of Valladolid is a multidisciplinary international group consisting of telecommunications, informatics and medical doctors from different specialties.</small> \n
|
444 |
+
|
445 |
+
<br>
|
446 |
+
|
447 |
+
<b>Email :e-mail: </b> : deevynkar@gmail.com''', unsafe_allow_html=True)
|
448 |
+
|
requirements (1).txt
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
altair==4.2.0
|
2 |
+
ants==0.0.7
|
3 |
+
antspynet==0.2.0
|
4 |
+
antspyx==0.3.5
|
5 |
+
matplotlib==3.6.2
|
6 |
+
monai==1.1.0
|
7 |
+
nibabel==4.0.2
|
8 |
+
numpy==1.23.1
|
9 |
+
pandas==1.5.2
|
10 |
+
PyWavelets==1.4.1
|
11 |
+
PyYAML==6.0
|
12 |
+
retrying==1.3.4
|
13 |
+
rich==12.6.0
|
14 |
+
scikit-image==0.19.3
|
15 |
+
scikit-learn==1.2.0
|
16 |
+
scipy==1.9.3
|
17 |
+
semver==2.13.0
|
18 |
+
smmap==5.0.0
|
19 |
+
sqlparse==0.4.3
|
20 |
+
statsmodels==0.13.5
|
21 |
+
streamlit==1.16.0
|
22 |
+
tenacity==8.1.0
|
23 |
+
tensorflow-probability==0.12.2
|
24 |
+
torch==1.13.1
|
25 |
+
watchdog==2.2.0
|
26 |
+
tensorflow==2.10.0
|
unilogo.png
ADDED