Spaces:
Running on Zero
Running on Zero
Upload app.py
Browse files
app.py
CHANGED
|
@@ -31,7 +31,6 @@ PARAMS = {
|
|
| 31 |
"points_per_batch": 32,
|
| 32 |
"min_mask_region_area": 4500,
|
| 33 |
"box_nms_thresh": 0.8,
|
| 34 |
-
"crops_n_layers": 1,
|
| 35 |
}
|
| 36 |
|
| 37 |
|
|
@@ -68,7 +67,6 @@ def segmentar(
|
|
| 68 |
points_per_batch: int,
|
| 69 |
min_mask_region_area: int,
|
| 70 |
box_nms_thresh: float,
|
| 71 |
-
crops_n_layers: int,
|
| 72 |
):
|
| 73 |
global PARAMS
|
| 74 |
if imagen is None:
|
|
@@ -81,7 +79,6 @@ def segmentar(
|
|
| 81 |
"points_per_batch": int(points_per_batch),
|
| 82 |
"min_mask_region_area": int(min_mask_region_area),
|
| 83 |
"box_nms_thresh": float(box_nms_thresh),
|
| 84 |
-
"crops_n_layers": int(crops_n_layers),
|
| 85 |
})
|
| 86 |
|
| 87 |
_load_pipeline()
|
|
@@ -93,7 +90,6 @@ def segmentar(
|
|
| 93 |
stability_score_thresh=PARAMS["stability_score_thresh"],
|
| 94 |
min_mask_region_area=PARAMS["min_mask_region_area"],
|
| 95 |
box_nms_thresh=PARAMS["box_nms_thresh"],
|
| 96 |
-
crops_n_layers=PARAMS["crops_n_layers"],
|
| 97 |
)
|
| 98 |
if isinstance(resultado, list):
|
| 99 |
resultado = resultado[0]
|
|
@@ -105,7 +101,7 @@ def segmentar(
|
|
| 105 |
info = (
|
| 106 |
f"UI: {len(masks)} zonas | "
|
| 107 |
f"iou={PARAMS['pred_iou_thresh']} stab={PARAMS['stability_score_thresh']} "
|
| 108 |
-
f"
|
| 109 |
f"nms={PARAMS['box_nms_thresh']} batch={PARAMS['points_per_batch']}"
|
| 110 |
)
|
| 111 |
return _render_masks(imagen_rgb, masks), info
|
|
@@ -137,7 +133,6 @@ def segment_for_backend(image_np: np.ndarray):
|
|
| 137 |
stability_score_thresh=PARAMS["stability_score_thresh"],
|
| 138 |
min_mask_region_area=PARAMS["min_mask_region_area"],
|
| 139 |
box_nms_thresh=PARAMS["box_nms_thresh"],
|
| 140 |
-
crops_n_layers=PARAMS["crops_n_layers"],
|
| 141 |
)
|
| 142 |
if isinstance(resultado, list):
|
| 143 |
resultado = resultado[0]
|
|
@@ -229,12 +224,8 @@ with gr.Blocks(title="SAM Auto - Segmentacion") as demo:
|
|
| 229 |
minimum=0.0, maximum=1.0, step=0.05, value=PARAMS["box_nms_thresh"],
|
| 230 |
label="box_nms_thresh (↑ permite mas solapamiento entre mascaras)"
|
| 231 |
)
|
| 232 |
-
sl_crops = gr.Slider(
|
| 233 |
-
minimum=0, maximum=2, step=1, value=PARAMS["crops_n_layers"],
|
| 234 |
-
label="crops_n_layers (0=imagen completa · 1=+4 recortes · 2=+16 recortes, lento)"
|
| 235 |
-
)
|
| 236 |
|
| 237 |
-
all_inputs = [imagen_entrada, sl_pred_iou, sl_stability, sl_batch, sl_min_area, sl_nms
|
| 238 |
boton.click(fn=segmentar, inputs=all_inputs, outputs=[imagen_salida, estado])
|
| 239 |
imagen_entrada.upload(fn=segmentar, inputs=all_inputs, outputs=[imagen_salida, estado])
|
| 240 |
|
|
|
|
| 31 |
"points_per_batch": 32,
|
| 32 |
"min_mask_region_area": 4500,
|
| 33 |
"box_nms_thresh": 0.8,
|
|
|
|
| 34 |
}
|
| 35 |
|
| 36 |
|
|
|
|
| 67 |
points_per_batch: int,
|
| 68 |
min_mask_region_area: int,
|
| 69 |
box_nms_thresh: float,
|
|
|
|
| 70 |
):
|
| 71 |
global PARAMS
|
| 72 |
if imagen is None:
|
|
|
|
| 79 |
"points_per_batch": int(points_per_batch),
|
| 80 |
"min_mask_region_area": int(min_mask_region_area),
|
| 81 |
"box_nms_thresh": float(box_nms_thresh),
|
|
|
|
| 82 |
})
|
| 83 |
|
| 84 |
_load_pipeline()
|
|
|
|
| 90 |
stability_score_thresh=PARAMS["stability_score_thresh"],
|
| 91 |
min_mask_region_area=PARAMS["min_mask_region_area"],
|
| 92 |
box_nms_thresh=PARAMS["box_nms_thresh"],
|
|
|
|
| 93 |
)
|
| 94 |
if isinstance(resultado, list):
|
| 95 |
resultado = resultado[0]
|
|
|
|
| 101 |
info = (
|
| 102 |
f"UI: {len(masks)} zonas | "
|
| 103 |
f"iou={PARAMS['pred_iou_thresh']} stab={PARAMS['stability_score_thresh']} "
|
| 104 |
+
f"min_area={PARAMS['min_mask_region_area']} "
|
| 105 |
f"nms={PARAMS['box_nms_thresh']} batch={PARAMS['points_per_batch']}"
|
| 106 |
)
|
| 107 |
return _render_masks(imagen_rgb, masks), info
|
|
|
|
| 133 |
stability_score_thresh=PARAMS["stability_score_thresh"],
|
| 134 |
min_mask_region_area=PARAMS["min_mask_region_area"],
|
| 135 |
box_nms_thresh=PARAMS["box_nms_thresh"],
|
|
|
|
| 136 |
)
|
| 137 |
if isinstance(resultado, list):
|
| 138 |
resultado = resultado[0]
|
|
|
|
| 224 |
minimum=0.0, maximum=1.0, step=0.05, value=PARAMS["box_nms_thresh"],
|
| 225 |
label="box_nms_thresh (↑ permite mas solapamiento entre mascaras)"
|
| 226 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 227 |
|
| 228 |
+
all_inputs = [imagen_entrada, sl_pred_iou, sl_stability, sl_batch, sl_min_area, sl_nms]
|
| 229 |
boton.click(fn=segmentar, inputs=all_inputs, outputs=[imagen_salida, estado])
|
| 230 |
imagen_entrada.upload(fn=segmentar, inputs=all_inputs, outputs=[imagen_salida, estado])
|
| 231 |
|