Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
@@ -40,13 +40,17 @@ async def segment(req: SegmentRequest):
|
|
40 |
inputs["original_sizes"].cpu(),
|
41 |
inputs["reshaped_input_sizes"].cpu()
|
42 |
)
|
43 |
-
|
44 |
-
mask_np = (
|
45 |
-
.to(torch.uint8)
|
46 |
-
.cpu()
|
47 |
-
|
|
|
|
|
|
|
48 |
buf = io.BytesIO()
|
49 |
-
|
50 |
buf.seek(0)
|
51 |
|
|
|
52 |
return StreamingResponse(buf, media_type="image/png")
|
|
|
40 |
inputs["original_sizes"].cpu(),
|
41 |
inputs["reshaped_input_sizes"].cpu()
|
42 |
)
|
43 |
+
single_mask = masks[0][0] # first image, first mask → torch.Tensor of shape (H, W)
|
44 |
+
mask_np = (single_mask * 255) \
|
45 |
+
.to(torch.uint8) \
|
46 |
+
.cpu().numpy()
|
47 |
+
|
48 |
+
# now mask_np.shape == (H, W), e.g. (10, 10)
|
49 |
+
print(mask_np.shape)
|
50 |
+
pil_mask = Image.fromarray(mask_np[0,:,:])
|
51 |
buf = io.BytesIO()
|
52 |
+
pil_mask.save(buf, format="PNG")
|
53 |
buf.seek(0)
|
54 |
|
55 |
+
|
56 |
return StreamingResponse(buf, media_type="image/png")
|