mouseland commited on
Commit
c08aa90
·
verified ·
1 Parent(s): e16c5c4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -3
app.py CHANGED
@@ -131,12 +131,38 @@ def run_model_gpu(img):
131
  masks, flows, _ = model.eval(img, channels = [0,0])
132
  return masks, flows
133
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
134
  #@spaces.GPU(duration=10)
135
- def cellpose_segment(img_pil):
136
  img_input = imread(img_pil)
137
  #img_input = np.array(img_pil)
138
- img = image_resize(img_input)
139
- masks, flows = run_model_gpu(img)
 
 
 
 
 
 
 
 
 
 
 
140
  #masks, flows, _ = model.eval(img, channels=[0,0])
141
  flows = flows[0]
142
  # masks = np.zeros(img.shape[:2])
 
131
  masks, flows, _ = model.eval(img, channels = [0,0])
132
  return masks, flows
133
 
134
+ @spaces.GPU(duration=60)
135
+ def run_model_gpu60(img):
136
+ masks, flows, _ = model.eval(img, channels = [0,0])
137
+ return masks, flows
138
+
139
+ @spaces.GPU(duration=240)
140
+ def run_model_gpu240(img):
141
+ masks, flows, _ = model.eval(img, channels = [0,0])
142
+ return masks, flows
143
+
144
+ @spaces.GPU(duration=1000)
145
+ def run_model_gpu1000(img):
146
+ masks, flows, _ = model.eval(img, channels = [0,0])
147
+ return masks, flows
148
+
149
  #@spaces.GPU(duration=10)
150
+ def cellpose_segment(img_pil, resize = 900):
151
  img_input = imread(img_pil)
152
  #img_input = np.array(img_pil)
153
+ img = image_resize(img_input, resize = resize)
154
+
155
+ resize = np.max(img.shape)
156
+ if resize<1000:
157
+ masks, flows = run_model_gpu(img)
158
+ elif resize < 5000:
159
+ masks, flows = run_model_gpu60(img)
160
+ elif resize < 20000:
161
+ masks, flows = run_model_gpu240(img)
162
+ else:
163
+ raise ValueError("Image size must be less than 20,000")
164
+
165
+
166
  #masks, flows, _ = model.eval(img, channels=[0,0])
167
  flows = flows[0]
168
  # masks = np.zeros(img.shape[:2])