feat: add field-specific bbox expansion strategies for YOLO training
Implement center-point based bbox scaling with directional compensation to capture field labels that typically appear above or to the left of field values. This improves YOLO training data quality by including contextual information around field values. Key changes: - Add shared.bbox module with ScaleStrategy dataclass and expand_bbox function - Define field-specific strategies (ocr_number, bankgiro, invoice_date, etc.) - Support manual_mode for minimal padding (no scaling) - Integrate expand_bbox into AnnotationGenerator - Add FIELD_TO_CLASS mapping for field_name to class_name lookup - Comprehensive tests with 100% coverage (45 tests) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -16,6 +16,7 @@ from shared.fields import (
|
||||
FIELD_CLASSES,
|
||||
FIELD_CLASS_IDS,
|
||||
CLASS_TO_FIELD,
|
||||
FIELD_TO_CLASS,
|
||||
CSV_TO_CLASS_MAPPING,
|
||||
TRAINING_FIELD_CLASSES,
|
||||
NUM_CLASSES,
|
||||
@@ -133,6 +134,20 @@ class TestMappingConsistency:
|
||||
assert fd.field_name in TRAINING_FIELD_CLASSES
|
||||
assert TRAINING_FIELD_CLASSES[fd.field_name] == fd.class_id
|
||||
|
||||
def test_field_to_class_is_inverse_of_class_to_field(self):
|
||||
"""Verify FIELD_TO_CLASS and CLASS_TO_FIELD are proper inverses."""
|
||||
for class_name, field_name in CLASS_TO_FIELD.items():
|
||||
assert FIELD_TO_CLASS[field_name] == class_name
|
||||
|
||||
for field_name, class_name in FIELD_TO_CLASS.items():
|
||||
assert CLASS_TO_FIELD[class_name] == field_name
|
||||
|
||||
def test_field_to_class_has_all_fields(self):
|
||||
"""Verify FIELD_TO_CLASS has mapping for all field names."""
|
||||
for fd in FIELD_DEFINITIONS:
|
||||
assert fd.field_name in FIELD_TO_CLASS
|
||||
assert FIELD_TO_CLASS[fd.field_name] == fd.class_name
|
||||
|
||||
|
||||
class TestSpecificFieldDefinitions:
|
||||
"""Tests for specific field definitions to catch common mistakes."""
|
||||
|
||||
Reference in New Issue
Block a user