Spaces:
Runtime error
Runtime error
update _compute arguments and logic
Browse files- iliauniiccocrevaluation.py +17 -5
iliauniiccocrevaluation.py
CHANGED
@@ -17,7 +17,7 @@ import datasets
|
|
17 |
import evaluate
|
18 |
|
19 |
# TODO: Add BibTeX citation
|
20 |
-
from ocr_evaluation.evaluate.metrics import evaluate_by_words
|
21 |
from ocr_evaluation.ocr.fiftyone import FiftyOneOcr
|
22 |
|
23 |
_CITATION = """\
|
@@ -181,16 +181,28 @@ class IliauniIccOCREvaluation(evaluate.Metric):
|
|
181 |
# TODO: Download external resources if needed
|
182 |
pass
|
183 |
|
184 |
-
def _compute(self, predictions, references):
|
185 |
"""Returns the scores"""
|
186 |
|
|
|
|
|
|
|
|
|
187 |
assert len(predictions) == len(references)
|
188 |
results = []
|
189 |
for prediction, reference in zip(predictions, references):
|
190 |
-
prediction_df = FiftyOneOcr(data=prediction).
|
191 |
-
reference_df = FiftyOneOcr(data=reference).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
192 |
|
193 |
-
result = evaluate_by_words(prediction_df, reference_df, pref1="Pred_", pref2="Tar_")
|
194 |
results.append(result)
|
195 |
|
196 |
return results
|
|
|
17 |
import evaluate
|
18 |
|
19 |
# TODO: Add BibTeX citation
|
20 |
+
from ocr_evaluation.evaluate.metrics import evaluate_by_symbols, evaluate_by_words, evaluate_by_word_groups,
|
21 |
from ocr_evaluation.ocr.fiftyone import FiftyOneOcr
|
22 |
|
23 |
_CITATION = """\
|
|
|
181 |
# TODO: Download external resources if needed
|
182 |
pass
|
183 |
|
184 |
+
def _compute(self, *, predictions=None, references=None, **kwargs):
|
185 |
"""Returns the scores"""
|
186 |
|
187 |
+
eval_method = "word"
|
188 |
+
if kwargs.get("eval_method", "word") in ["symbol", "word", "word_group"]:
|
189 |
+
eval_method = kwargs["eval_method"]
|
190 |
+
|
191 |
assert len(predictions) == len(references)
|
192 |
results = []
|
193 |
for prediction, reference in zip(predictions, references):
|
194 |
+
prediction_df = FiftyOneOcr(data=prediction).get_detections(convert_bbox=True)
|
195 |
+
reference_df = FiftyOneOcr(data=reference).get_detections(convert_bbox=True)
|
196 |
+
|
197 |
+
if eval_method == "symbol":
|
198 |
+
result = evaluate_by_symbols(prediction_df, reference_df, pref1="Pred_", pref2="Tar_")
|
199 |
+
elif eval_method == "word":
|
200 |
+
result = evaluate_by_words(prediction_df, reference_df, pref1="Pred_", pref2="Tar_")
|
201 |
+
elif eval_method == "word_group":
|
202 |
+
result = evaluate_by_word_groups(prediction_df, reference_df, pref1="Pred_", pref2="Tar_")
|
203 |
+
else:
|
204 |
+
result = {}
|
205 |
|
|
|
206 |
results.append(result)
|
207 |
|
208 |
return results
|