Spaces:
Running
on
Zero
Running
on
Zero
fix seg
Browse files
app.py
CHANGED
@@ -70,7 +70,6 @@ def get_random_seed(randomize_seed, seed):
|
|
70 |
@spaces.GPU(duration=10)
|
71 |
def process_image(image_path):
|
72 |
image = cv2.imread(image_path, cv2.IMREAD_UNCHANGED)
|
73 |
-
image = cv2.resize(image, (518, 518), interpolation=cv2.INTER_AREA)
|
74 |
if image.shape[-1] == 4:
|
75 |
image = cv2.cvtColor(image, cv2.COLOR_BGRA2RGBA)
|
76 |
else:
|
@@ -79,6 +78,7 @@ def process_image(image_path):
|
|
79 |
image = rembg.remove(image, session=bg_remover) # [H, W, 4]
|
80 |
mask = image[..., -1] > 0
|
81 |
image = recenter_foreground(image, mask, border_ratio=0.1)
|
|
|
82 |
image = image.astype(np.float32) / 255.0
|
83 |
image = image[..., :3] * image[..., 3:4] + (1 - image[..., 3:4]) # white background
|
84 |
image = (image * 255).astype(np.uint8)
|
@@ -166,8 +166,8 @@ with block:
|
|
166 |
with gr.Column(scale=1):
|
167 |
with gr.Row():
|
168 |
# input image
|
169 |
-
input_image = gr.Image(label="Input Image", type="filepath") # use file_path and load manually
|
170 |
-
seg_image = gr.Image(label="Segmentation Result", type="numpy", interactive=False)
|
171 |
with gr.Accordion("Settings", open=True):
|
172 |
# inference steps
|
173 |
num_steps = gr.Slider(label="Inference steps", minimum=1, maximum=100, step=1, value=50)
|
|
|
70 |
@spaces.GPU(duration=10)
|
71 |
def process_image(image_path):
|
72 |
image = cv2.imread(image_path, cv2.IMREAD_UNCHANGED)
|
|
|
73 |
if image.shape[-1] == 4:
|
74 |
image = cv2.cvtColor(image, cv2.COLOR_BGRA2RGBA)
|
75 |
else:
|
|
|
78 |
image = rembg.remove(image, session=bg_remover) # [H, W, 4]
|
79 |
mask = image[..., -1] > 0
|
80 |
image = recenter_foreground(image, mask, border_ratio=0.1)
|
81 |
+
image = cv2.resize(image, (518, 518), interpolation=cv2.INTER_AREA)
|
82 |
image = image.astype(np.float32) / 255.0
|
83 |
image = image[..., :3] * image[..., 3:4] + (1 - image[..., 3:4]) # white background
|
84 |
image = (image * 255).astype(np.uint8)
|
|
|
166 |
with gr.Column(scale=1):
|
167 |
with gr.Row():
|
168 |
# input image
|
169 |
+
input_image = gr.Image(label="Input Image", type="filepath", image_mode="RGBA") # use file_path and load manually
|
170 |
+
seg_image = gr.Image(label="Segmentation Result", type="numpy", interactive=False, image_mode="RGBA")
|
171 |
with gr.Accordion("Settings", open=True):
|
172 |
# inference steps
|
173 |
num_steps = gr.Slider(label="Inference steps", minimum=1, maximum=100, step=1, value=50)
|