Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -20,11 +20,7 @@ model = UNet(
|
|
20 |
model.load_state_dict(torch.load("best_model.pth", map_location=torch.device('cpu')))
|
21 |
model.eval()
|
22 |
|
23 |
-
def
|
24 |
-
|
25 |
-
|
26 |
-
# image = Image.open(image_path).convert("RGB")
|
27 |
-
# image = np.array(image) / 255.0
|
28 |
image = image / 255.0
|
29 |
image = image.astype(np.float32)
|
30 |
|
@@ -32,39 +28,34 @@ def greet(image):
|
|
32 |
A.Resize(height=512, width=512),
|
33 |
ToTensorV2(),
|
34 |
])
|
35 |
-
|
36 |
image = inference_transforms(image=image)["image"]
|
37 |
-
print(image.shape)
|
38 |
image = image.unsqueeze(0)
|
39 |
|
40 |
-
|
41 |
with torch.no_grad():
|
42 |
mask_pred = torch.sigmoid(model(image))
|
43 |
|
44 |
-
print(image.shape)
|
45 |
-
print(mask_pred.shape)
|
46 |
-
print(mask_pred[0, 0, :, :].shape)
|
47 |
return mask_pred[0, 0, :, :].numpy()
|
48 |
|
49 |
|
50 |
demo = gr.Interface(
|
51 |
-
fn=
|
52 |
title="Histapathology segmentation",
|
53 |
inputs=[
|
54 |
gr.Image(
|
55 |
label="Input image",
|
56 |
image_mode="RGB",
|
57 |
-
|
58 |
type="numpy",
|
59 |
-
|
60 |
)
|
61 |
],
|
62 |
outputs=[
|
63 |
gr.Image(
|
64 |
label="Model Prediction",
|
65 |
image_mode="L",
|
66 |
-
|
67 |
-
|
68 |
)
|
69 |
],
|
70 |
# examples=[
|
|
|
20 |
model.load_state_dict(torch.load("best_model.pth", map_location=torch.device('cpu')))
|
21 |
model.eval()
|
22 |
|
23 |
+
def process_image(image):
|
|
|
|
|
|
|
|
|
24 |
image = image / 255.0
|
25 |
image = image.astype(np.float32)
|
26 |
|
|
|
28 |
A.Resize(height=512, width=512),
|
29 |
ToTensorV2(),
|
30 |
])
|
31 |
+
|
32 |
image = inference_transforms(image=image)["image"]
|
|
|
33 |
image = image.unsqueeze(0)
|
34 |
|
|
|
35 |
with torch.no_grad():
|
36 |
mask_pred = torch.sigmoid(model(image))
|
37 |
|
|
|
|
|
|
|
38 |
return mask_pred[0, 0, :, :].numpy()
|
39 |
|
40 |
|
41 |
demo = gr.Interface(
|
42 |
+
fn=process_image,
|
43 |
title="Histapathology segmentation",
|
44 |
inputs=[
|
45 |
gr.Image(
|
46 |
label="Input image",
|
47 |
image_mode="RGB",
|
48 |
+
height=400,
|
49 |
type="numpy",
|
50 |
+
width=400,
|
51 |
)
|
52 |
],
|
53 |
outputs=[
|
54 |
gr.Image(
|
55 |
label="Model Prediction",
|
56 |
image_mode="L",
|
57 |
+
height=400,
|
58 |
+
width=400,
|
59 |
)
|
60 |
],
|
61 |
# examples=[
|