Sempy32 commited on
Commit
1c31152
·
verified ·
1 Parent(s): 57f5873

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +5 -4
app.py CHANGED
@@ -27,7 +27,7 @@ def _encode_mask(mask_bool: np.ndarray) -> str:
27
 
28
 
29
  @spaces.GPU(duration=120)
30
- def api_panoptic(image, concepts, conf):
31
  if image is None:
32
  return {"error": "no image provided"}
33
  image = image.convert("RGB")
@@ -43,7 +43,7 @@ def api_panoptic(image, concepts, conf):
43
  target_sizes = (inputs["original_sizes"].tolist()
44
  if "original_sizes" in inputs else [[H, W]])
45
  res = processor.post_process_instance_segmentation(
46
- outputs, threshold=float(conf), mask_threshold=0.5,
47
  target_sizes=target_sizes)[0]
48
  # NOTE (verify on live Space): expected keys masks/scores/boxes.
49
  masks, scores = res["masks"], res["scores"]
@@ -69,8 +69,9 @@ with gr.Blocks(title="SAM3 Panoptic") as demo:
69
  out = gr.JSON(label="Detections")
70
  txt = gr.Textbox(label="Concepts (comma-separated)",
71
  value="person, car, road, sky, building, tree")
72
- conf = gr.Slider(0.0, 1.0, value=0.4, step=0.05, label="Confidence")
73
- gr.Button("Segment").click(api_panoptic, [inp, txt, conf], out,
 
74
  api_name="api_panoptic")
75
 
76
  if __name__ == "__main__":
 
27
 
28
 
29
  @spaces.GPU(duration=120)
30
+ def api_panoptic(image, concepts, conf, mask_threshold=0.5):
31
  if image is None:
32
  return {"error": "no image provided"}
33
  image = image.convert("RGB")
 
43
  target_sizes = (inputs["original_sizes"].tolist()
44
  if "original_sizes" in inputs else [[H, W]])
45
  res = processor.post_process_instance_segmentation(
46
+ outputs, threshold=float(conf), mask_threshold=float(mask_threshold),
47
  target_sizes=target_sizes)[0]
48
  # NOTE (verify on live Space): expected keys masks/scores/boxes.
49
  masks, scores = res["masks"], res["scores"]
 
69
  out = gr.JSON(label="Detections")
70
  txt = gr.Textbox(label="Concepts (comma-separated)",
71
  value="person, car, road, sky, building, tree")
72
+ conf = gr.Slider(0.0, 1.0, value=0.4, step=0.05, label="Confidence (lower = more detail)")
73
+ mthr = gr.Slider(0.05, 0.95, value=0.5, step=0.05, label="Mask threshold")
74
+ gr.Button("Segment").click(api_panoptic, [inp, txt, conf, mthr], out,
75
  api_name="api_panoptic")
76
 
77
  if __name__ == "__main__":