Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -55,6 +55,29 @@ def process_scan(path):
|
|
55 |
volume = resize_volume(volume)
|
56 |
return volume
|
57 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
def infer(filename):
|
59 |
vol = process_scan(filename.name)
|
60 |
vol = np.expand_dims(vol, axis=0)
|
@@ -67,17 +90,17 @@ def infer(filename):
|
|
67 |
for score, name in zip(scores, class_names):
|
68 |
result = result + [f"This model is {(100 * score):.2f} percent confident that CT scan is {name}"]
|
69 |
|
70 |
-
return result
|
71 |
|
72 |
model = from_pretrained_keras('jalFaizy/3D_CNN')
|
73 |
|
74 |
-
|
75 |
-
|
76 |
|
77 |
iface = gr.Interface(
|
78 |
infer,
|
79 |
-
|
80 |
-
|
81 |
title='3D CNN for CT scans',
|
82 |
examples=['example_1_normal.nii.gz']
|
83 |
)
|
|
|
55 |
volume = resize_volume(volume)
|
56 |
return volume
|
57 |
|
58 |
+
def plot_slices(num_rows, num_columns, width, height, data):
|
59 |
+
"""Plot a montage of 20 CT slices"""
|
60 |
+
data = np.rot90(np.array(data))
|
61 |
+
data = np.transpose(data)
|
62 |
+
data = np.reshape(data, (num_rows, num_columns, width, height))
|
63 |
+
rows_data, columns_data = data.shape[0], data.shape[1]
|
64 |
+
heights = [slc[0].shape[0] for slc in data]
|
65 |
+
widths = [slc.shape[1] for slc in data[0]]
|
66 |
+
fig_width = 12.0
|
67 |
+
fig_height = fig_width * sum(heights) / sum(widths)
|
68 |
+
f, axarr = plt.subplots(
|
69 |
+
rows_data,
|
70 |
+
columns_data,
|
71 |
+
figsize=(fig_width, fig_height),
|
72 |
+
gridspec_kw={"height_ratios": heights},
|
73 |
+
)
|
74 |
+
for i in range(rows_data):
|
75 |
+
for j in range(columns_data):
|
76 |
+
axarr[i, j].imshow(data[i][j], cmap="gray")
|
77 |
+
axarr[i, j].axis("off")
|
78 |
+
|
79 |
+
return f
|
80 |
+
|
81 |
def infer(filename):
|
82 |
vol = process_scan(filename.name)
|
83 |
vol = np.expand_dims(vol, axis=0)
|
|
|
90 |
for score, name in zip(scores, class_names):
|
91 |
result = result + [f"This model is {(100 * score):.2f} percent confident that CT scan is {name}"]
|
92 |
|
93 |
+
return result, plot_slices(2, 10, 128, 128, vol[0, :, :, :20])
|
94 |
|
95 |
model = from_pretrained_keras('jalFaizy/3D_CNN')
|
96 |
|
97 |
+
inputs = gr.inputs.File()
|
98 |
+
outputs = [gr.outputs.Textbox(), 'plot']
|
99 |
|
100 |
iface = gr.Interface(
|
101 |
infer,
|
102 |
+
inputs,
|
103 |
+
outputs,
|
104 |
title='3D CNN for CT scans',
|
105 |
examples=['example_1_normal.nii.gz']
|
106 |
)
|