qubvel-hf HF staff commited on
Commit
b53f046
·
verified ·
1 Parent(s): 65bfcd0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -0
app.py CHANGED
@@ -40,12 +40,19 @@ def process_image(image: PIL.Image.Image) -> tuple[PIL.Image.Image, list[dict]]:
40
  )
41
  result = results[0] # take first image results
42
  boxes_xyxy = result["boxes"].cpu().numpy()
 
 
 
 
 
43
 
44
  detections = sv.Detections(xyxy=boxes_xyxy)
45
  bounding_box_annotator = sv.BoxAnnotator(color=sv.Color.WHITE, color_lookup=sv.ColorLookup.INDEX, thickness=1)
 
46
 
47
  # annotate bounding boxes
48
  annotated_frame = bounding_box_annotator.annotate(scene=image.copy(), detections=detections)
 
49
 
50
  return annotated_frame
51
 
 
40
  )
41
  result = results[0] # take first image results
42
  boxes_xyxy = result["boxes"].cpu().numpy()
43
+ indexes = result["labels"].cpu().numpy()
44
+ scores = result["scores"].cpu().numpy()
45
+ text_labels = [
46
+ f"{model.id2label[index]} [{score.item():.2f}]" for index, score in zip(indexes, scores)
47
+ ]
48
 
49
  detections = sv.Detections(xyxy=boxes_xyxy)
50
  bounding_box_annotator = sv.BoxAnnotator(color=sv.Color.WHITE, color_lookup=sv.ColorLookup.INDEX, thickness=1)
51
+ label_annotator = sv.LabelAnnotator()
52
 
53
  # annotate bounding boxes
54
  annotated_frame = bounding_box_annotator.annotate(scene=image.copy(), detections=detections)
55
+ annotated_frame = label_annotator(scene=annotated_frame, detections=detections, labels=text_labels)
56
 
57
  return annotated_frame
58