jbilcke-hf commited on
Commit
550276f
·
1 Parent(s): 3dda9fb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -31
app.py CHANGED
@@ -546,23 +546,20 @@ def run_anything_task(input_image, text_prompt, box_threshold, text_threshold,
546
  plt.figure(figsize=(10, 10))
547
  # we don't draw the background image, we only want the mask
548
  # plt.imshow(image)
549
- boxes_with_labels = zip(boxes_filt, pred_phrases)
550
 
551
  results = []
552
 
553
-
554
  for i, mask in enumerate(masks):
555
  color = np.concatenate([np.random.random(3), np.array([0.6])], axis=0)
556
  # color = np.array([30/255, 144/255, 255/255, 0.6])
557
  show_mask(mask.cpu().numpy(), plt.gca(), color)
558
- item = {
559
  "id": i,
560
- "box": boxes_with_labels[i][0].tolist(),
561
- "label": boxes_with_labels[i][1],
562
  "color": color
563
- }
564
- results.append(item)
565
- for box, label in boxes_with_labels:
566
  show_box(box.cpu().numpy(), plt.gca(), label)
567
  plt.axis('off')
568
  image_path = os.path.join(output_dir, f"grounding_seg_output_{file_temp}.png")
@@ -571,29 +568,7 @@ def run_anything_task(input_image, text_prompt, box_threshold, text_threshold,
571
  os.remove(image_path)
572
  output_images.append(segment_image_result)
573
 
574
- result_list = []
575
- for i, box in enumerate(boxes_filt):
576
- label, score = pred_phrases[i][:-6], float(pred_phrases[i][-4:-1]) # assuming 'roof(0.70)' format
577
- print("label: " + label)
578
- print("score: " + str(score))
579
- print(box.tolist())
580
- result_list.append({
581
- "id": i,
582
- "label": label,
583
- "score": score,
584
- "box": box.tolist()
585
- })
586
-
587
- debug = {
588
- "thing1": boxes_filt.size(0),
589
- "thing2": boxes_with_labels,
590
- "thing3": pred_phrases,
591
- "results": results,
592
- "result_list": result_list,
593
-
594
- }
595
-
596
- return debug, output_images, gr.Gallery.update(label='result images')
597
 
598
  if __name__ == "__main__":
599
  parser = argparse.ArgumentParser("Grounded SAM demo", add_help=True)
 
546
  plt.figure(figsize=(10, 10))
547
  # we don't draw the background image, we only want the mask
548
  # plt.imshow(image)
 
549
 
550
  results = []
551
 
 
552
  for i, mask in enumerate(masks):
553
  color = np.concatenate([np.random.random(3), np.array([0.6])], axis=0)
554
  # color = np.array([30/255, 144/255, 255/255, 0.6])
555
  show_mask(mask.cpu().numpy(), plt.gca(), color)
556
+ results.append({
557
  "id": i,
558
+ "box": boxes_filt[i].tolist(),
559
+ "label": pred_phrases[i],
560
  "color": color
561
+ })
562
+ for box, label in zip(boxes_filt, pred_phrases):
 
563
  show_box(box.cpu().numpy(), plt.gca(), label)
564
  plt.axis('off')
565
  image_path = os.path.join(output_dir, f"grounding_seg_output_{file_temp}.png")
 
568
  os.remove(image_path)
569
  output_images.append(segment_image_result)
570
 
571
+ return results, output_images, gr.Gallery.update(label='result images')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
572
 
573
  if __name__ == "__main__":
574
  parser = argparse.ArgumentParser("Grounded SAM demo", add_help=True)