Spaces:
Running
on
Zero
Running
on
Zero
Upload app.py
Browse files
app.py
CHANGED
@@ -140,7 +140,6 @@ def button_clickable(selected_points):
|
|
140 |
return gr.Button.update(interactive=False)
|
141 |
|
142 |
|
143 |
-
@spaces.GPU(duration=90)
|
144 |
def run_sam(predictor: SamPredictor, selected_points):
|
145 |
"""
|
146 |
调用 SAM 模型进行分割。
|
@@ -158,7 +157,6 @@ def run_sam(predictor: SamPredictor, selected_points):
|
|
158 |
visible_mask = 255 * np.squeeze(masks).astype(np.uint8)
|
159 |
return visible_mask, None
|
160 |
|
161 |
-
@spaces.GPU
|
162 |
def apply_mask_overlay(image, mask):
|
163 |
"""
|
164 |
在原图上叠加 mask:使用红色绘制 mask 的轮廓,非 mask 区域叠加浅灰色半透明遮罩。
|
@@ -174,7 +172,6 @@ def apply_mask_overlay(image, mask):
|
|
174 |
cv2.drawContours(overlay, contours, -1, (255, 0, 0), 2)
|
175 |
return overlay
|
176 |
|
177 |
-
@spaces.GPU
|
178 |
def segment_and_overlay(image, points, sam_predictor):
|
179 |
"""
|
180 |
调用 run_sam 获得 mask,然后叠加显示分割结果。
|
@@ -349,7 +346,6 @@ def split_image(image: Image.Image) -> list:
|
|
349 |
images.append(Image.fromarray(image[:, s:e+1]))
|
350 |
return [image for image in images]
|
351 |
|
352 |
-
@spaces.GPU
|
353 |
def get_sam_predictor():
|
354 |
sam_checkpoint = hf_hub_download("ybelkada/segment-anything", "checkpoints/sam_vit_h_4b8939.pth")
|
355 |
model_type = "vit_h"
|
|
|
140 |
return gr.Button.update(interactive=False)
|
141 |
|
142 |
|
|
|
143 |
def run_sam(predictor: SamPredictor, selected_points):
|
144 |
"""
|
145 |
调用 SAM 模型进行分割。
|
|
|
157 |
visible_mask = 255 * np.squeeze(masks).astype(np.uint8)
|
158 |
return visible_mask, None
|
159 |
|
|
|
160 |
def apply_mask_overlay(image, mask):
|
161 |
"""
|
162 |
在原图上叠加 mask:使用红色绘制 mask 的轮廓,非 mask 区域叠加浅灰色半透明遮罩。
|
|
|
172 |
cv2.drawContours(overlay, contours, -1, (255, 0, 0), 2)
|
173 |
return overlay
|
174 |
|
|
|
175 |
def segment_and_overlay(image, points, sam_predictor):
|
176 |
"""
|
177 |
调用 run_sam 获得 mask,然后叠加显示分割结果。
|
|
|
346 |
images.append(Image.fromarray(image[:, s:e+1]))
|
347 |
return [image for image in images]
|
348 |
|
|
|
349 |
def get_sam_predictor():
|
350 |
sam_checkpoint = hf_hub_download("ybelkada/segment-anything", "checkpoints/sam_vit_h_4b8939.pth")
|
351 |
model_type = "vit_h"
|