Files
Oleksandr Bezdieniezhnykh 142c6c4de8 Refactor constants management to use Pydantic BaseModel for configuration
- Replaced module-level path variables in constants.py with a structured Pydantic Config class.
- Updated all relevant modules (train.py, augmentation.py, exports.py, dataset-visualiser.py, manual_run.py) to access paths through the new config structure.
- Fixed bugs related to image processing and model saving.
- Enhanced test infrastructure to accommodate the new configuration approach.

This refactor improves code maintainability and clarity by centralizing configuration management.
2026-03-27 18:18:30 +02:00

2.3 KiB
Raw Permalink Blame History

Component: Data Models

Overview

Shared data transfer objects for the training pipeline: annotation class definitions (with weather modes) and image+label containers for visualization and augmentation.

Pattern: Plain data classes / value objects Upstream: None (leaf) Downstream: Data Pipeline (augmentation, dataset-visualiser), Training (YAML generation)

Modules

  • dto/annotationClass — AnnotationClass, WeatherMode enum, classes.json reader
  • dto/imageLabel — ImageLabel container with bbox visualization

Internal Interfaces

WeatherMode (Enum)

Member Value Description
Norm 0 Normal weather
Wint 20 Winter
Night 40 Night

AnnotationClass

AnnotationClass(id: int, name: str, color: str)
AnnotationClass.read_json() -> dict[int, AnnotationClass]  # static
AnnotationClass.color_tuple -> tuple  # property, RGB ints

ImageLabel

ImageLabel(image_path: str, image: np.ndarray, labels_path: str, labels: list)
ImageLabel.visualize(annotation_classes: dict) -> None

Data Access Patterns

  • AnnotationClass.read_json() reads classes.json from project root (relative to dto/ parent)
  • ImageLabel.visualize() renders to matplotlib window (no disk I/O)

Implementation Details

  • 17 base annotation classes × 3 weather modes = 51 classes with offset IDs (016, 2036, 4056)
  • System reserves 80 class slots (DEFAULT_CLASS_NUM in train.py)
  • YOLO label format: [x_center, y_center, width, height, class_id] — all normalized 01
  • color_tuple parsing strips first 3 chars (assumes "#ff" prefix format) — fragile if color format changes

Caveats

  • AnnotationClass duplicated in 3 locations (dto, inference/dto, annotation-queue/annotation_queue_dto) with slight differences
  • color_tuple property has a non-obvious parsing approach that may break on different color string formats
  • Empty files: dto/annotation_bulk_message.py and dto/annotation_message.py suggest planned but unimplemented DTOs

Dependency Graph

graph TD
    dto_annotationClass[dto/annotationClass] --> train
    dto_annotationClass --> dataset-visualiser
    dto_imageLabel[dto/imageLabel] --> augmentation
    dto_imageLabel --> dataset-visualiser

Logging Strategy

None.