chris-propeller commited on
Commit
edcc62f
·
1 Parent(s): a45e44e

rename to point_labels

Browse files
Files changed (2) hide show
  1. README.md +2 -1
  2. app.py +13 -9
README.md CHANGED
@@ -103,10 +103,11 @@ result = response.json()
103
 
104
  // SAM2 COMPATIBLE: Point-based prompts
105
  "points": [[[x1, y1]], [[x2, y2]]], // Points for each object
106
- "labels": [[1], [1]], // Labels for each point (1=foreground, 0=background)
107
 
108
  // SAM2 COMPATIBLE: Bounding box prompts
109
  "boxes": [[x1, y1, x2, y2], [x1, y1, x2, y2]], // Bounding boxes
 
110
 
111
  "multimask_output": false, // Optional, defaults to False
112
  "confidence_threshold": 0.5 // Optional, minimum confidence for returned masks
 
103
 
104
  // SAM2 COMPATIBLE: Point-based prompts
105
  "points": [[[x1, y1]], [[x2, y2]]], // Points for each object
106
+ "point_labels": [[1], [1]], // Labels for each point (1=foreground, 0=background)
107
 
108
  // SAM2 COMPATIBLE: Bounding box prompts
109
  "boxes": [[x1, y1, x2, y2], [x1, y1, x2, y2]], // Bounding boxes
110
+ "box_labels": [1, 0], // Labels for each box (1=positive, 0=negative/exclude)
111
 
112
  "multimask_output": false, // Optional, defaults to False
113
  "confidence_threshold": 0.5 // Optional, minimum confidence for returned masks
app.py CHANGED
@@ -241,8 +241,9 @@ def sam2_compatible_api(data):
241
  image_b64 = inputs_data.get("image")
242
  text_prompts = inputs_data.get("text_prompts", [])
243
  input_points = inputs_data.get("points", [])
244
- input_labels = inputs_data.get("labels", [])
245
  input_boxes = inputs_data.get("boxes", [])
 
246
  confidence_threshold = inputs_data.get("confidence_threshold", 0.5)
247
  vectorize = inputs_data.get("vectorize", False)
248
  simplify_epsilon = inputs_data.get("simplify_epsilon", 2.0)
@@ -252,14 +253,17 @@ def sam2_compatible_api(data):
252
  return {"error": "No image provided", "success": False}
253
 
254
  has_text = bool(text_prompts)
255
- has_points = bool(input_points and input_labels)
256
  has_boxes = bool(input_boxes)
257
 
258
  if not (has_text or has_points or has_boxes):
259
- return {"error": "Must provide at least one prompt type: text_prompts, points+labels, or boxes", "success": False}
260
 
261
- if has_points and len(input_points) != len(input_labels):
262
- return {"error": "Number of points and labels must match", "success": False}
 
 
 
263
 
264
  # Decode image
265
  if image_b64.startswith('data:image'):
@@ -313,9 +317,9 @@ def sam2_compatible_api(data):
313
  # Process visual prompts (boxes and/or points) - can be combined in a single call
314
  if has_boxes or has_points:
315
  combined_boxes = input_boxes if has_boxes else None
316
- combined_box_labels = inputs_data.get("box_labels", [1] * len(input_boxes)) if has_boxes else None
317
  combined_points = input_points if has_points else None
318
- combined_point_labels = input_labels if has_points else None
319
 
320
  results = sam3_inference(
321
  image=image,
@@ -506,7 +510,7 @@ response = requests.post(
506
  "boxes": [[50, 50, 150, 150]], # Bounding box
507
  "box_labels": [0], # 0=negative (exclude this area)
508
  "points": [[200, 200]], # Point prompt
509
- "labels": [1], # 1=positive point
510
  "confidence_threshold": 0.5
511
  }
512
  }
@@ -541,7 +545,7 @@ result = response.json()
541
 
542
  // SAM2 COMPATIBLE: Point-based prompts (can be combined with text/boxes)
543
  "points": [[x1, y1], [x2, y2]], // Individual points (not nested arrays)
544
- "labels": [1, 0], // Labels for each point (1=positive/foreground, 0=negative/background)
545
 
546
  // SAM2 COMPATIBLE: Bounding box prompts (can be combined with text/points)
547
  "boxes": [[x1, y1, x2, y2], [x3, y3, x4, y4]], // Bounding boxes
 
241
  image_b64 = inputs_data.get("image")
242
  text_prompts = inputs_data.get("text_prompts", [])
243
  input_points = inputs_data.get("points", [])
244
+ input_point_labels = inputs_data.get("point_labels", [])
245
  input_boxes = inputs_data.get("boxes", [])
246
+ input_box_labels = inputs_data.get("box_labels", [])
247
  confidence_threshold = inputs_data.get("confidence_threshold", 0.5)
248
  vectorize = inputs_data.get("vectorize", False)
249
  simplify_epsilon = inputs_data.get("simplify_epsilon", 2.0)
 
253
  return {"error": "No image provided", "success": False}
254
 
255
  has_text = bool(text_prompts)
256
+ has_points = bool(input_points and input_point_labels)
257
  has_boxes = bool(input_boxes)
258
 
259
  if not (has_text or has_points or has_boxes):
260
+ return {"error": "Must provide at least one prompt type: text_prompts, points+point_labels, or boxes", "success": False}
261
 
262
+ if has_points and len(input_points) != len(input_point_labels):
263
+ return {"error": "Number of points and point_labels must match", "success": False}
264
+
265
+ if has_boxes and input_box_labels and len(input_boxes) != len(input_box_labels):
266
+ return {"error": "Number of boxes and box_labels must match", "success": False}
267
 
268
  # Decode image
269
  if image_b64.startswith('data:image'):
 
317
  # Process visual prompts (boxes and/or points) - can be combined in a single call
318
  if has_boxes or has_points:
319
  combined_boxes = input_boxes if has_boxes else None
320
+ combined_box_labels = input_box_labels if (has_boxes and input_box_labels) else ([1] * len(input_boxes) if has_boxes else None)
321
  combined_points = input_points if has_points else None
322
+ combined_point_labels = input_point_labels if has_points else None
323
 
324
  results = sam3_inference(
325
  image=image,
 
510
  "boxes": [[50, 50, 150, 150]], # Bounding box
511
  "box_labels": [0], # 0=negative (exclude this area)
512
  "points": [[200, 200]], # Point prompt
513
+ "point_labels": [1], # 1=positive point
514
  "confidence_threshold": 0.5
515
  }
516
  }
 
545
 
546
  // SAM2 COMPATIBLE: Point-based prompts (can be combined with text/boxes)
547
  "points": [[x1, y1], [x2, y2]], // Individual points (not nested arrays)
548
+ "point_labels": [1, 0], // Labels for each point (1=positive/foreground, 0=negative/background)
549
 
550
  // SAM2 COMPATIBLE: Bounding box prompts (can be combined with text/points)
551
  "boxes": [[x1, y1, x2, y2], [x3, y3, x4, y4]], // Bounding boxes