Yao Zhang commited on
Commit
9c5adc2
·
1 Parent(s): 1aef684
__pycache__/unetr2d.cpython-37.pyc ADDED
Binary file (3.73 kB). View file
 
app.py CHANGED
@@ -18,6 +18,7 @@ from monai.inferers import sliding_window_inference
18
  from unetr2d import UNETR2D
19
  import time
20
  from skimage import io, segmentation, morphology, measure, exposure
 
21
 
22
 
23
  def visualize_instance_seg_mask(mask):
@@ -130,19 +131,27 @@ def get_seg(pre_img_data, model_name, custom_model_path, threshold):
130
  return test_pred_mask
131
 
132
 
133
- def predict(img, threshold):
134
- print('##########', img)
135
- seg_labels = get_seg(preprocess(img), 'swinunetr', './best_Dice_model.pth', float(threshold))
136
- seg_labels = visualize_instance_seg_mask(seg_labels)
137
- return seg_labels, './text.tif'
 
 
 
 
 
 
 
 
138
 
139
 
140
  demo = gr.Interface(
141
  predict,
142
  # inputs=[gr.Image()],
143
  # inputs="file",
144
- inputs=[gr.File(), gr.Number()]
145
- outputs=[gr.Image(), gr.File()],
146
  title="NeurIPS CellSeg Demo",
147
  # examples=[["cell_00225.png"]]
148
  )
 
18
  from unetr2d import UNETR2D
19
  import time
20
  from skimage import io, segmentation, morphology, measure, exposure
21
+ import tifffile as tif
22
 
23
 
24
  def visualize_instance_seg_mask(mask):
 
131
  return test_pred_mask
132
 
133
 
134
+ def predict(img, threshold=0.5):
135
+ print('##########', img.name)
136
+ img_name = img.name
137
+ if img_name.endswith('.tif') or img_name.endswith('.tiff'):
138
+ img_data = tif.imread(img_name)
139
+ else:
140
+ img_data = io.imread(img_name)
141
+ seg_labels = get_seg(preprocess(img_data), 'swinunetr', './best_Dice_model.pth', float(threshold))
142
+ seg_rgb = visualize_instance_seg_mask(seg_labels)
143
+
144
+ tif.imwrite(join(os.getcwd(), 'segmentation.tiff'), seg_labels, compression='zlib')
145
+
146
+ return img_data, seg_rgb, join(os.getcwd(), 'segmentation.tiff')
147
 
148
 
149
  demo = gr.Interface(
150
  predict,
151
  # inputs=[gr.Image()],
152
  # inputs="file",
153
+ inputs=[gr.File(label="input image"), gr.Slider(minimum=0, maximum=1, value=0.5, step=0.1, label="threshold")],
154
+ outputs=[gr.Image(label="image"), gr.Image(label="segmentation"), gr.File(label="download segmentation")],
155
  title="NeurIPS CellSeg Demo",
156
  # examples=[["cell_00225.png"]]
157
  )
segmentation.tiff ADDED