taskswithcode commited on
Commit
bfa6130
·
1 Parent(s): 656949c
Files changed (1) hide show
  1. app.py +6 -4
app.py CHANGED
@@ -33,9 +33,11 @@ def query_image(img, text_queries,max_results):
33
  results = processor.post_process(outputs=outputs, target_sizes=target_sizes)
34
  boxes, scores, labels = results[0]["boxes"], results[0]["scores"], results[0]["labels"]
35
  results_dict = {}
 
36
  for box, score, label in zip(boxes, scores, labels):
37
- results_dict[score] = {"box":box,"label":label}
38
- sorted_results_dict = OrderedDict(sorted(results_dict.items(),reverse=True))
 
39
 
40
 
41
  font = cv2.FONT_HERSHEY_SIMPLEX
@@ -43,7 +45,7 @@ def query_image(img, text_queries,max_results):
43
  score_dist = []
44
  count = 0
45
  for score in sorted_results_dict:
46
- score_dist.append(round(score.tolist(),2))
47
  count += 1
48
  if (count == 10):
49
  break
@@ -64,7 +66,7 @@ def query_image(img, text_queries,max_results):
64
  else:
65
  y = box[3] + 25
66
 
67
- rounded_score = round(score.tolist(),2)
68
  img = cv2.putText(
69
  img, f"({rounded_score}):{text_queries[label]}", (box[0], y), font, .5, (255,0,0), 1, cv2.LINE_AA
70
  )
 
33
  results = processor.post_process(outputs=outputs, target_sizes=target_sizes)
34
  boxes, scores, labels = results[0]["boxes"], results[0]["scores"], results[0]["labels"]
35
  results_dict = {}
36
+ count = 0
37
  for box, score, label in zip(boxes, scores, labels):
38
+ results_dict[count] = {"score":score.tolist(),"box":box,"label":label}
39
+ count += 1
40
+ sorted_results_dict = OrderedDict(sorted(results_dict.items(),key=lambda item: item[1]["score"],reverse=True))
41
 
42
 
43
  font = cv2.FONT_HERSHEY_SIMPLEX
 
45
  score_dist = []
46
  count = 0
47
  for score in sorted_results_dict:
48
+ score_dist.append(round(score,2))
49
  count += 1
50
  if (count == 10):
51
  break
 
66
  else:
67
  y = box[3] + 25
68
 
69
+ rounded_score = round(score,2)
70
  img = cv2.putText(
71
  img, f"({rounded_score}):{text_queries[label]}", (box[0], y), font, .5, (255,0,0), 1, cv2.LINE_AA
72
  )