Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -237,16 +237,16 @@ def predict_wsi(image):
|
|
| 237 |
@spaces.GPU(duration=120)
|
| 238 |
def segment_image(image):
|
| 239 |
img = image
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
img = np.pad(img, ((0, pad_h), (0, pad_w), (0, 0)), mode='constant', constant_values=0)
|
| 249 |
|
|
|
|
| 250 |
if (np.max(img) > 100):
|
| 251 |
img = img / 255.0
|
| 252 |
transform = T.Compose([T.ToTensor()])
|
|
|
|
| 237 |
@spaces.GPU(duration=120)
|
| 238 |
def segment_image(image):
|
| 239 |
img = image
|
| 240 |
+
|
| 241 |
+
# resize if necessary
|
| 242 |
+
min_side=768
|
| 243 |
+
w, h = image.size
|
| 244 |
+
if min(w, h) < min_side:
|
| 245 |
+
scale = min_side / min(w, h)
|
| 246 |
+
new_w, new_h = int(w * scale), int(h * scale)
|
| 247 |
+
img = img.resize((new_w, new_h), Image.ANTIALIAS)
|
|
|
|
| 248 |
|
| 249 |
+
img = np.asarray(img)
|
| 250 |
if (np.max(img) > 100):
|
| 251 |
img = img / 255.0
|
| 252 |
transform = T.Compose([T.ToTensor()])
|