Make sure that 0 cer and wer are reported

pull/47/head
Benjamin Rosemann 4 years ago
parent fd6f57a263
commit c9219cbacd

@ -40,13 +40,13 @@
{% if metrics %}
<h2>Metrics</h2>
{% if cer %}
{% if cer is not none %}
<p>CER: {{ cer|round(4) }}</p>
{% endif %}
{% if wer %}
{% if wer is not none %}
<p>WER: {{ wer|round(4) }}</p>
{% endif %}
{% if fca %}
{% if fca is not none %}
<p>FCA: {{ fca|round(4) }}</p>
{% endif %}
{% endif %}

@ -1,10 +1,10 @@
{
{% if metrics %}
{% if cer %}"cer": {{ cer|json_float }},{% endif %}
{% if wer %}"wer": {{ wer|json_float }},{% endif %}
{% if fca %}"fca": {{ fca|json_float }},{% endif %}
{% if n_characters %}"n_characters": {{ n_characters }},{% endif %}
{% if n_words %}"n_words": {{ n_words }},{% endif %}
{% if cer is not none %}"cer": {{ cer|json_float }},{% endif %}
{% if wer is not none %}"wer": {{ wer|json_float }},{% endif %}
{% if fca is not none %}"fca": {{ fca|json_float }},{% endif %}
{% if n_characters is not none %}"n_characters": {{ n_characters }},{% endif %}
{% if n_words is not none %}"n_words": {{ n_words }},{% endif %}
{% endif %}
"gt": "{{ gt }}",
"ocr": "{{ ocr }}"

@ -58,3 +58,18 @@ def test_cli_json_cer_is_infinity(tmp_path):
j = json.load(jsonf)
assert j["cer"] == pytest.approx(float("inf"))
assert j["fca"] == pytest.approx(-13)
def test_cli_json_cer_0_in_report(tmp_path):
"""Test that the cli/process() yields a loadable JSON report when CER == 0"""
with working_directory(str(tmp_path)):
with open("gt.txt", "w") as gtf:
gtf.write("Lorem Ipsum")
process("gt.txt", "gt.txt", "report", metrics="cer,wer,fca")
with open("report.json", "r") as jsonf:
j = json.load(jsonf)
assert j["cer"] == pytest.approx(0)
assert j["wer"] == pytest.approx(0)
assert j["fca"] == pytest.approx(1)

Loading…
Cancel
Save