haritsahm
commited on
Commit
•
4adfcec
1
Parent(s):
4191136
code cleanup
Browse files
app.py
CHANGED
@@ -38,26 +38,26 @@ def visualize_instance_seg_mask(mask):
|
|
38 |
def query_image(img):
|
39 |
data = {"image": img}
|
40 |
batch = preprocess(data)
|
41 |
-
|
42 |
network.eval()
|
43 |
with torch.no_grad():
|
44 |
pred = inference(batch['image'].unsqueeze(dim=0), network)
|
45 |
-
|
46 |
batch["pred"] = pred
|
47 |
for k,v in batch["pred"].items():
|
48 |
batch["pred"][k] = v.squeeze(dim=0)
|
49 |
-
|
50 |
batch = postprocess(batch)
|
51 |
-
|
52 |
result = visualize_instance_seg_mask(batch["type_map"].squeeze())
|
53 |
-
|
54 |
# Combine image
|
55 |
result = batch["image"].permute(1, 2, 0).cpu().numpy() * 0.5 + result * 0.5
|
56 |
-
|
57 |
# Solve rotating problem
|
58 |
result = np.fliplr(result)
|
59 |
result = np.rot90(result, k=1)
|
60 |
-
|
61 |
return result
|
62 |
|
63 |
# load Markdown file
|
@@ -66,11 +66,11 @@ with open('Description.md','r') as file:
|
|
66 |
|
67 |
demo = gr.Interface(
|
68 |
query_image,
|
69 |
-
inputs=[gr.Image(type="filepath")],
|
70 |
outputs="image",
|
71 |
title="Medical Image Classification with MONAI - Pathology Nuclei Segmentation Classification",
|
72 |
description = markdown_content,
|
73 |
-
examples=example_files
|
74 |
)
|
75 |
|
76 |
demo.queue(concurrency_count=20).launch()
|
|
|
38 |
def query_image(img):
|
39 |
data = {"image": img}
|
40 |
batch = preprocess(data)
|
41 |
+
|
42 |
network.eval()
|
43 |
with torch.no_grad():
|
44 |
pred = inference(batch['image'].unsqueeze(dim=0), network)
|
45 |
+
|
46 |
batch["pred"] = pred
|
47 |
for k,v in batch["pred"].items():
|
48 |
batch["pred"][k] = v.squeeze(dim=0)
|
49 |
+
|
50 |
batch = postprocess(batch)
|
51 |
+
|
52 |
result = visualize_instance_seg_mask(batch["type_map"].squeeze())
|
53 |
+
|
54 |
# Combine image
|
55 |
result = batch["image"].permute(1, 2, 0).cpu().numpy() * 0.5 + result * 0.5
|
56 |
+
|
57 |
# Solve rotating problem
|
58 |
result = np.fliplr(result)
|
59 |
result = np.rot90(result, k=1)
|
60 |
+
|
61 |
return result
|
62 |
|
63 |
# load Markdown file
|
|
|
66 |
|
67 |
demo = gr.Interface(
|
68 |
query_image,
|
69 |
+
inputs=[gr.Image(type="filepath")],
|
70 |
outputs="image",
|
71 |
title="Medical Image Classification with MONAI - Pathology Nuclei Segmentation Classification",
|
72 |
description = markdown_content,
|
73 |
+
examples=example_files,
|
74 |
)
|
75 |
|
76 |
demo.queue(concurrency_count=20).launch()
|