Updated to newest gradio version and version fixed the dependencies.
Browse files- .gitignore +3 -1
- app.py +3 -18
- requirements.txt +3 -3
.gitignore
CHANGED
@@ -1 +1,3 @@
|
|
1 |
-
.vscode
|
|
|
|
|
|
1 |
+
.vscode
|
2 |
+
app_copy.py
|
3 |
+
__pycache__
|
app.py
CHANGED
@@ -1,6 +1,3 @@
|
|
1 |
-
# AUTOGENERATED! DO NOT EDIT! File to edit: ../main.ipynb.
|
2 |
-
|
3 |
-
# %% auto 0
|
4 |
__all__ = [
|
5 |
"ORGAN",
|
6 |
"IMAGE_SIZE",
|
@@ -23,7 +20,6 @@ __all__ = [
|
|
23 |
"to_oberlay_image",
|
24 |
]
|
25 |
|
26 |
-
# %% ../main.ipynb 1
|
27 |
import numpy as np
|
28 |
import pandas as pd
|
29 |
import skimage
|
@@ -32,7 +28,6 @@ import segmentation_models_pytorch as smp
|
|
32 |
|
33 |
import gradio as gr
|
34 |
|
35 |
-
# %% ../main.ipynb 2
|
36 |
ORGAN = "kidney"
|
37 |
IMAGE_SIZE = 512
|
38 |
MODEL_NAME = "unetpp_b4_th60_d9414.pkl"
|
@@ -40,7 +35,6 @@ THRESHOLD = float(MODEL_NAME.split("_")[2][2:]) / 100.0
|
|
40 |
CODES = ["Background", "FTU"] # FTU = functional tissue unit
|
41 |
|
42 |
|
43 |
-
# %% ../main.ipynb 3
|
44 |
def x_getter(r):
|
45 |
return r["fnames"]
|
46 |
|
@@ -59,11 +53,9 @@ def splitter(model):
|
|
59 |
return L([enc_params, untrained_params])
|
60 |
|
61 |
|
62 |
-
# %% ../main.ipynb 4
|
63 |
learn = load_learner(MODEL_NAME)
|
64 |
|
65 |
|
66 |
-
# %% ../main.ipynb 5
|
67 |
def make3D(t: np.array) -> np.array:
|
68 |
t = np.expand_dims(t, axis=2)
|
69 |
t = np.concatenate((t, t, t), axis=2)
|
@@ -126,7 +118,6 @@ def to_oberlay_image(data):
|
|
126 |
return img
|
127 |
|
128 |
|
129 |
-
# %% ../main.ipynb 6
|
130 |
title = "Glomerulus Segmentation"
|
131 |
description = """
|
132 |
A web app that segments glomeruli in histological kidney slices!
|
@@ -137,24 +128,18 @@ The provided example images are random subset of kidney slices from the [Human P
|
|
137 |
|
138 |
Here is my corresponding [blog post](https://fhatje.github.io/posts/glomseg/train_model.html).
|
139 |
"""
|
140 |
-
|
141 |
examples = [str(p) for p in get_image_files("example_images")]
|
142 |
interpretation = "default"
|
143 |
|
144 |
-
# %% ../main.ipynb 7
|
145 |
demo = gr.Interface(
|
146 |
fn=predict,
|
147 |
-
inputs=gr.components.Image(
|
148 |
outputs=[gr.components.Image(), gr.components.DataFrame()],
|
149 |
title=title,
|
150 |
description=description,
|
151 |
examples=examples,
|
152 |
-
interpretation=interpretation,
|
153 |
-
# Fixes error when set to True:
|
154 |
-
# https://github.com/gradio-app/gradio/pull/1949
|
155 |
-
# but generated file names are too long
|
156 |
-
_api_mode=False,
|
157 |
)
|
158 |
|
159 |
-
# %% ../main.ipynb 9
|
160 |
demo.launch()
|
|
|
|
|
|
|
|
|
1 |
__all__ = [
|
2 |
"ORGAN",
|
3 |
"IMAGE_SIZE",
|
|
|
20 |
"to_oberlay_image",
|
21 |
]
|
22 |
|
|
|
23 |
import numpy as np
|
24 |
import pandas as pd
|
25 |
import skimage
|
|
|
28 |
|
29 |
import gradio as gr
|
30 |
|
|
|
31 |
ORGAN = "kidney"
|
32 |
IMAGE_SIZE = 512
|
33 |
MODEL_NAME = "unetpp_b4_th60_d9414.pkl"
|
|
|
35 |
CODES = ["Background", "FTU"] # FTU = functional tissue unit
|
36 |
|
37 |
|
|
|
38 |
def x_getter(r):
|
39 |
return r["fnames"]
|
40 |
|
|
|
53 |
return L([enc_params, untrained_params])
|
54 |
|
55 |
|
|
|
56 |
learn = load_learner(MODEL_NAME)
|
57 |
|
58 |
|
|
|
59 |
def make3D(t: np.array) -> np.array:
|
60 |
t = np.expand_dims(t, axis=2)
|
61 |
t = np.concatenate((t, t, t), axis=2)
|
|
|
118 |
return img
|
119 |
|
120 |
|
|
|
121 |
title = "Glomerulus Segmentation"
|
122 |
description = """
|
123 |
A web app that segments glomeruli in histological kidney slices!
|
|
|
128 |
|
129 |
Here is my corresponding [blog post](https://fhatje.github.io/posts/glomseg/train_model.html).
|
130 |
"""
|
131 |
+
|
132 |
examples = [str(p) for p in get_image_files("example_images")]
|
133 |
interpretation = "default"
|
134 |
|
|
|
135 |
demo = gr.Interface(
|
136 |
fn=predict,
|
137 |
+
inputs=gr.components.Image(width=IMAGE_SIZE, height=IMAGE_SIZE),
|
138 |
outputs=[gr.components.Image(), gr.components.DataFrame()],
|
139 |
title=title,
|
140 |
description=description,
|
141 |
examples=examples,
|
142 |
+
# interpretation=interpretation,
|
|
|
|
|
|
|
|
|
143 |
)
|
144 |
|
|
|
145 |
demo.launch()
|
requirements.txt
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
-
fastai
|
2 |
-
scikit-image
|
3 |
-
segmentation-models-pytorch
|
|
|
1 |
+
fastai==2.9.7
|
2 |
+
scikit-image==0.19.3
|
3 |
+
segmentation-models-pytorch==0.3.0
|