Gladiator commited on
Commit
fb058b3
·
1 Parent(s): 51f706a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -11
app.py CHANGED
@@ -5,18 +5,24 @@ from PIL import Image
5
  from cellpose import models
6
 
7
 
8
- def inference(img, model_path, **model_params):
9
- inf_model = models.CellposeModel(gpu=False, pretrained_model=model_path)
10
- preds, flows, _ = inf_model.eval([img], **model_params)
11
- return preds, flows
 
 
 
 
 
12
 
13
 
14
  if __name__ == "__main__":
15
 
16
  st.title("Sartorius Neuronal Cell Segmentation")
17
-
 
18
  uploaded_img = st.file_uploader(label="Upload neuronal cell image")
19
-
20
  with st.expander("View input image"):
21
  if uploaded_img is not None:
22
  st.image(uploaded_img)
@@ -36,11 +42,12 @@ if __name__ == "__main__":
36
  "resample": True,
37
  }
38
  with st.spinner("Performing segmentation. This might take a while..."):
39
- preds, flows = inference(
40
- img=img,
41
- model_path="./cellpose_residual_on_style_on_concatenation_off_fold1_ep_649_cv_0.2834",
42
- **model_params
43
- )
 
44
 
45
  fig, (ax1, ax2, ax3) = plt.subplots(1, 3)
46
  ax1.axis("off")
 
5
  from cellpose import models
6
 
7
 
8
+ @st.cache()
9
+ def load_model(model_path):
10
+ inf_model = models.CellposeModel(gpu=False, pretrained_model=model_path)
11
+ return inf_model
12
+
13
+ #def inference(img, model_path, **model_params):
14
+ # inf_model = models.CellposeModel(gpu=False, pretrained_model=model_path)
15
+ # preds, flows, _ = inf_model.eval([img], **model_params)
16
+ # return preds, flows
17
 
18
 
19
  if __name__ == "__main__":
20
 
21
  st.title("Sartorius Neuronal Cell Segmentation")
22
+
23
+ inf_model = models.CellposeModel(gpu=False, pretrained_model=model_path)
24
  uploaded_img = st.file_uploader(label="Upload neuronal cell image")
25
+
26
  with st.expander("View input image"):
27
  if uploaded_img is not None:
28
  st.image(uploaded_img)
 
42
  "resample": True,
43
  }
44
  with st.spinner("Performing segmentation. This might take a while..."):
45
+ #preds, flows = inference(
46
+ # img=img,
47
+ # model_path="./cellpose_residual_on_style_on_concatenation_off_fold1_ep_649_cv_0.2834",
48
+ # **model_params
49
+ #)
50
+ preds, flows, _ = inf_model.eval([img], **model_params)
51
 
52
  fig, (ax1, ax2, ax3) = plt.subplots(1, 3)
53
  ax1.axis("off")