Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions doctr/io/elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,9 +401,11 @@ def __init__(
lines = []
if artefacts is None:
artefacts = []
# Compute the objectness score of the line
# Compute the objectness score of the block
if objectness_score is None:
objectness_score = float(np.mean([w.objectness_score for line in lines for w in line.words]))
# A block without any word (only artefacts) takes the confidence of its artefacts, instead of NaN
scores = [w.objectness_score for line in lines for w in line.words] or [a.confidence for a in artefacts]
objectness_score = float(np.mean(scores))
# Resolve the geometry using the smallest enclosing bounding box
if geometry is None:
line_boxes = [word.geometry for line in lines for word in line.words]
Expand Down
3 changes: 3 additions & 0 deletions tests/common/test_io_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,9 @@ def test_block_artefacts_only():
assert block.lines == []
assert block.geometry == ((0, 0), (1, 1))
assert block.render() == ""
# The objectness score is the confidence of the artefacts, which keeps the export valid JSON
assert block.objectness_score == 0.8
json.loads(json.dumps(block.export(), allow_nan=False))


def test_block_rotated_lines_from_dict():
Expand Down
Loading