Added example CT to demo
Browse files- .gitignore +1 -1
- Dockerfile +3 -0
- demo/app.py +5 -2
- demo/src/compute.py +1 -2
- demo/src/gui.py +22 -4
.gitignore
CHANGED
@@ -13,4 +13,4 @@ gradio_cached_examples/
|
|
13 |
flagged/
|
14 |
files/
|
15 |
*.csv
|
16 |
-
*.obj
|
|
|
13 |
flagged/
|
14 |
files/
|
15 |
*.csv
|
16 |
+
*.obj
|
Dockerfile
CHANGED
@@ -53,4 +53,7 @@ COPY --chown=user . $HOME/app
|
|
53 |
# Download pretrained parenchyma model
|
54 |
RUN wget "https://github.com/andreped/livermask/releases/download/trained-models-v1/model.h5"
|
55 |
|
|
|
|
|
|
|
56 |
CMD ["python3.7", "demo/app.py"]
|
|
|
53 |
# Download pretrained parenchyma model
|
54 |
RUN wget "https://github.com/andreped/livermask/releases/download/trained-models-v1/model.h5"
|
55 |
|
56 |
+
# Download test sample
|
57 |
+
RUN python3.7 -m pip install gdown && gdown "https://drive.google.com/uc?id=1shjSrFjS4PHE5sTku30PZTLPZpGu24o3"
|
58 |
+
|
59 |
CMD ["python3.7", "demo/app.py"]
|
demo/app.py
CHANGED
@@ -4,11 +4,14 @@ from src.gui import WebUI
|
|
4 |
def main():
|
5 |
print("Launching demo...")
|
6 |
|
7 |
-
|
|
|
|
|
|
|
8 |
class_name = "parenchyma"
|
9 |
|
10 |
# initialize and run app
|
11 |
-
app = WebUI(model_name=model_name, class_name=class_name)
|
12 |
app.run()
|
13 |
|
14 |
|
|
|
4 |
def main():
|
5 |
print("Launching demo...")
|
6 |
|
7 |
+
cwd = "/Users/andreped/workspace/livermask/" # local testing -> macOS
|
8 |
+
# cwd = "/home/user/app/" # production -> docker
|
9 |
+
|
10 |
+
model_name = "model.h5" # assumed to lie in `cwd` directory
|
11 |
class_name = "parenchyma"
|
12 |
|
13 |
# initialize and run app
|
14 |
+
app = WebUI(model_name=model_name, class_name=class_name, cwd=cwd)
|
15 |
app.run()
|
16 |
|
17 |
|
demo/src/compute.py
CHANGED
@@ -1,6 +1,5 @@
|
|
1 |
|
2 |
|
3 |
-
def run_model(input_path, model_name
|
4 |
from livermask.utils.run import run_analysis
|
5 |
run_analysis(cpu=True, extension='.nii', path=input_path, output='prediction', verbose=True, vessels=False, name=model_name, mp_enabled=False)
|
6 |
-
|
|
|
1 |
|
2 |
|
3 |
+
def run_model(input_path, model_name):
|
4 |
from livermask.utils.run import run_analysis
|
5 |
run_analysis(cpu=True, extension='.nii', path=input_path, output='prediction', verbose=True, vessels=False, name=model_name, mp_enabled=False)
|
|
demo/src/gui.py
CHANGED
@@ -5,15 +5,17 @@ from .convert import nifti_to_glb
|
|
5 |
|
6 |
|
7 |
class WebUI:
|
8 |
-
def __init__(self, model_name, class_name):
|
9 |
# global states
|
10 |
self.images = []
|
11 |
self.pred_images = []
|
12 |
|
|
|
13 |
self.nb_slider_items = 100
|
14 |
|
15 |
self.model_name = model_name
|
16 |
self.class_name = class_name
|
|
|
17 |
|
18 |
# define widgets not to be rendered immediantly, but later on
|
19 |
self.slider = gr.Slider(1, self.nb_slider_items, value=1, step=1, label="Which 2D slice to show")
|
@@ -29,7 +31,7 @@ class WebUI:
|
|
29 |
def upload_file(self, file):
|
30 |
return file.name
|
31 |
|
32 |
-
def load_mesh(self, mesh_file_name, model_name
|
33 |
path = mesh_file_name.name
|
34 |
run_model(path, model_name)
|
35 |
nifti_to_glb("prediction-livermask.nii")
|
@@ -48,11 +50,27 @@ class WebUI:
|
|
48 |
with gr.Blocks() as demo:
|
49 |
|
50 |
with gr.Row().style(equal_height=True):
|
51 |
-
file_output = gr.File(
|
|
|
|
|
|
|
52 |
file_output.upload(self.upload_file, file_output, file_output)
|
53 |
|
54 |
run_btn = gr.Button("Run analysis").style(full_width=False, size="sm")
|
55 |
-
run_btn.click(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
|
57 |
with gr.Row().style(equal_height=True):
|
58 |
with gr.Box():
|
|
|
5 |
|
6 |
|
7 |
class WebUI:
|
8 |
+
def __init__(self, model_name:str = None, class_name:str = None, cwd:str = None):
|
9 |
# global states
|
10 |
self.images = []
|
11 |
self.pred_images = []
|
12 |
|
13 |
+
# @TODO: This should be dynamically set based on chosen volume size
|
14 |
self.nb_slider_items = 100
|
15 |
|
16 |
self.model_name = model_name
|
17 |
self.class_name = class_name
|
18 |
+
self.cwd = cwd
|
19 |
|
20 |
# define widgets not to be rendered immediantly, but later on
|
21 |
self.slider = gr.Slider(1, self.nb_slider_items, value=1, step=1, label="Which 2D slice to show")
|
|
|
31 |
def upload_file(self, file):
|
32 |
return file.name
|
33 |
|
34 |
+
def load_mesh(self, mesh_file_name, model_name):
|
35 |
path = mesh_file_name.name
|
36 |
run_model(path, model_name)
|
37 |
nifti_to_glb("prediction-livermask.nii")
|
|
|
50 |
with gr.Blocks() as demo:
|
51 |
|
52 |
with gr.Row().style(equal_height=True):
|
53 |
+
file_output = gr.File(
|
54 |
+
file_types=[".nii", ".nii.nz"],
|
55 |
+
file_count="single"
|
56 |
+
).style(full_width=False, size="sm")
|
57 |
file_output.upload(self.upload_file, file_output, file_output)
|
58 |
|
59 |
run_btn = gr.Button("Run analysis").style(full_width=False, size="sm")
|
60 |
+
run_btn.click(
|
61 |
+
fn=lambda x: self.load_mesh(x, model_name=self.cwd + self.model_name),
|
62 |
+
inputs=file_output,
|
63 |
+
outputs=self.volume_renderer
|
64 |
+
)
|
65 |
+
|
66 |
+
with gr.Row().style(equal_height=True):
|
67 |
+
gr.Examples(
|
68 |
+
examples=[self.cwd + "test-volume.nii"],
|
69 |
+
inputs=file_output,
|
70 |
+
outputs=file_output,
|
71 |
+
fn=self.upload_file,
|
72 |
+
cache_examples=True,
|
73 |
+
)
|
74 |
|
75 |
with gr.Row().style(equal_height=True):
|
76 |
with gr.Box():
|