jbilcke-hf commited on
Commit
3e21e04
·
1 Parent(s): 012a344

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -7
app.py CHANGED
@@ -547,18 +547,22 @@ def run_anything_task(input_image, text_prompt, box_threshold, text_threshold,
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
- debug = {
551
- "thing1": boxes_filt.size(0),
552
- "thing2": boxes_with_labels,
553
- "thing3": pred_phrases
554
- }
555
 
556
  results = []
557
-
 
558
  for mask in masks:
559
  color = np.concatenate([np.random.random(3), np.array([0.6])], axis=0)
560
  # color = np.array([30/255, 144/255, 255/255, 0.6])
561
  show_mask(mask.cpu().numpy(), plt.gca(), color)
 
 
 
 
 
 
 
 
562
  for box, label in boxes_with_labels:
563
  show_box(box.cpu().numpy(), plt.gca(), label)
564
  plt.axis('off')
@@ -570,11 +574,26 @@ def run_anything_task(input_image, text_prompt, box_threshold, text_threshold,
570
 
571
  result_list = []
572
  for i, box in enumerate(boxes_filt):
573
- label, score = pred_phrases[i][:-5], float(pred_phrases[i][-4:-1]) # assuming 'roof(0.70)' format
574
  print("label: " + label)
575
  print("score: " + str(score))
576
  print(box.tolist())
 
 
 
 
 
 
577
 
 
 
 
 
 
 
 
 
 
578
  return debug, output_images, gr.Gallery.update(label='result images')
579
 
580
  if __name__ == "__main__":
 
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
+ i = 0
554
  for mask in 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
+ i++
565
+ results.append(item)
566
  for box, label in boxes_with_labels:
567
  show_box(box.cpu().numpy(), plt.gca(), label)
568
  plt.axis('off')
 
574
 
575
  result_list = []
576
  for i, box in enumerate(boxes_filt):
577
+ label, score = pred_phrases[i][:-6], float(pred_phrases[i][-4:-1]) # assuming 'roof(0.70)' format
578
  print("label: " + label)
579
  print("score: " + str(score))
580
  print(box.tolist())
581
+ result_list.append({
582
+ "id": i,
583
+ "label": label,
584
+ "score": score,
585
+ "box": box.tolist()
586
+ })
587
 
588
+ debug = {
589
+ "thing1": boxes_filt.size(0),
590
+ "thing2": boxes_with_labels,
591
+ "thing3": pred_phrases,
592
+ "results": results,
593
+ "result_list": result_list,
594
+
595
+ }
596
+
597
  return debug, output_images, gr.Gallery.update(label='result images')
598
 
599
  if __name__ == "__main__":