Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -56,15 +56,15 @@ print("Model ready!")
|
|
| 56 |
# Image preprocess
|
| 57 |
##################
|
| 58 |
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
|
|
|
| 64 |
mean=[0.485, 0.456, 0.406],
|
| 65 |
std=[0.229, 0.224, 0.225]
|
| 66 |
)
|
| 67 |
-
])
|
| 68 |
|
| 69 |
def process_pil(img):
|
| 70 |
img = to_tensor(img)
|
|
@@ -110,7 +110,7 @@ def show_img(all_imgs, dropdown, bg, alpha_factor):
|
|
| 110 |
###########
|
| 111 |
# Inference
|
| 112 |
|
| 113 |
-
def inference(img
|
| 114 |
background = resize_pil(img)
|
| 115 |
|
| 116 |
img = process_pil(img)
|
|
@@ -215,7 +215,7 @@ with gr.Blocks(title=title) as app:
|
|
| 215 |
background = gr.Image(visible=False)
|
| 216 |
|
| 217 |
gr.Button("1) Generate Masks").click(fn=inference,
|
| 218 |
-
inputs=[input_img],
|
| 219 |
outputs=[img, all_masks, background])
|
| 220 |
|
| 221 |
gr.Button("2) Generate Transparent Mask (with Alpha Factor)").click(fn=show_img,
|
|
|
|
| 56 |
# Image preprocess
|
| 57 |
##################
|
| 58 |
|
| 59 |
+
to_tensor = transforms.ToTensor()
|
| 60 |
+
to_array = transforms.ToPILImage()
|
| 61 |
+
resize = transforms.Resize((512,512))
|
| 62 |
+
resize_small = transforms.Resize((369,369))
|
| 63 |
+
narmalize = transforms.Normalize
|
| 64 |
+
transform = transforms.Compose(
|
| 65 |
mean=[0.485, 0.456, 0.406],
|
| 66 |
std=[0.229, 0.224, 0.225]
|
| 67 |
)
|
|
|
|
| 68 |
|
| 69 |
def process_pil(img):
|
| 70 |
img = to_tensor(img)
|
|
|
|
| 110 |
###########
|
| 111 |
# Inference
|
| 112 |
|
| 113 |
+
def inference(img):
|
| 114 |
background = resize_pil(img)
|
| 115 |
|
| 116 |
img = process_pil(img)
|
|
|
|
| 215 |
background = gr.Image(visible=False)
|
| 216 |
|
| 217 |
gr.Button("1) Generate Masks").click(fn=inference,
|
| 218 |
+
inputs=[input_img, slider],
|
| 219 |
outputs=[img, all_masks, background])
|
| 220 |
|
| 221 |
gr.Button("2) Generate Transparent Mask (with Alpha Factor)").click(fn=show_img,
|