Spaces:
Sleeping
Sleeping
ITSAIDI
commited on
Commit
•
a35180c
1
Parent(s):
0de3957
xcs
Browse files- utilitis.py +10 -1
utilitis.py
CHANGED
@@ -73,6 +73,15 @@ def unnormalize_box(bbox, width, height):
|
|
73 |
width * (bbox[2] / 1000),
|
74 |
height * (bbox[3] / 1000),
|
75 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
def get_word(bboxes,image):
|
77 |
x_min, y_min, x_max, y_max = bboxes
|
78 |
roi = image.crop((x_min, y_min, x_max, y_max)) # Region of intrest
|
@@ -96,7 +105,7 @@ def get_Finale_results(offset_mapping,id2label,image,prediction_scores,predictio
|
|
96 |
for index, prediction, score, bbox in Final_prediction:
|
97 |
if prediction not in Final_results or score > Final_results[prediction][1]:
|
98 |
Final_results[prediction] = (index, score,bbox)
|
99 |
-
|
100 |
|
101 |
for final in Final_results:
|
102 |
Kalma = get_word(Final_results[final][2],image)
|
|
|
73 |
width * (bbox[2] / 1000),
|
74 |
height * (bbox[3] / 1000),
|
75 |
]
|
76 |
+
|
77 |
+
def drop_null_bbox(dictionary):
|
78 |
+
keys_to_drop = []
|
79 |
+
for key, (_, _, bbox_values) in dictionary.items():
|
80 |
+
if all(value == 0.0 for value in bbox_values):
|
81 |
+
keys_to_drop.append(key)
|
82 |
+
for key in keys_to_drop:
|
83 |
+
del dictionary[key]
|
84 |
+
|
85 |
def get_word(bboxes,image):
|
86 |
x_min, y_min, x_max, y_max = bboxes
|
87 |
roi = image.crop((x_min, y_min, x_max, y_max)) # Region of intrest
|
|
|
105 |
for index, prediction, score, bbox in Final_prediction:
|
106 |
if prediction not in Final_results or score > Final_results[prediction][1]:
|
107 |
Final_results[prediction] = (index, score,bbox)
|
108 |
+
drop_null_bbox(Final_results)
|
109 |
|
110 |
for final in Final_results:
|
111 |
Kalma = get_word(Final_results[final][2],image)
|