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.
This commit is contained in:
Oleksandr Bezdieniezhnykh
2026-03-27 18:18:30 +02:00
parent b68c07b540
commit 142c6c4de8
106 changed files with 5706 additions and 654 deletions
+2 -23
View File
@@ -8,35 +8,14 @@ _DATASET_IMAGES = _PROJECT_ROOT / "_docs/00_problem/input_data/dataset/images"
_DATASET_LABELS = _PROJECT_ROOT / "_docs/00_problem/input_data/dataset/labels"
_ONNX_MODEL = _PROJECT_ROOT / "_docs/00_problem/input_data/azaion.onnx"
_CLASSES_JSON = _PROJECT_ROOT / "classes.json"
_CONFIG_TEST = _PROJECT_ROOT / "config.test.yaml"
collect_ignore = ["security_test.py", "imagelabel_visualize_test.py"]
def apply_constants_patch(monkeypatch, base: Path):
import constants as c
from os import path
root = str(base.resolve())
azaion = path.join(root, "azaion")
monkeypatch.setattr(c, "azaion", azaion)
data_dir = path.join(azaion, "data")
monkeypatch.setattr(c, "data_dir", data_dir)
monkeypatch.setattr(c, "data_images_dir", path.join(data_dir, c.images))
monkeypatch.setattr(c, "data_labels_dir", path.join(data_dir, c.labels))
processed_dir = path.join(azaion, "data-processed")
monkeypatch.setattr(c, "processed_dir", processed_dir)
monkeypatch.setattr(c, "processed_images_dir", path.join(processed_dir, c.images))
monkeypatch.setattr(c, "processed_labels_dir", path.join(processed_dir, c.labels))
corrupted_dir = path.join(azaion, "data-corrupted")
monkeypatch.setattr(c, "corrupted_dir", corrupted_dir)
monkeypatch.setattr(c, "corrupted_images_dir", path.join(corrupted_dir, c.images))
monkeypatch.setattr(c, "corrupted_labels_dir", path.join(corrupted_dir, c.labels))
monkeypatch.setattr(c, "sample_dir", path.join(azaion, "data-sample"))
monkeypatch.setattr(c, "datasets_dir", path.join(azaion, "datasets"))
models_dir = path.join(azaion, "models")
monkeypatch.setattr(c, "models_dir", models_dir)
monkeypatch.setattr(c, "CURRENT_PT_MODEL", path.join(models_dir, f"{c.prefix[:-1]}.pt"))
monkeypatch.setattr(c, "CURRENT_ONNX_MODEL", path.join(models_dir, f"{c.prefix[:-1]}.onnx"))
monkeypatch.setattr(c, "config", c.Config.from_yaml(str(_CONFIG_TEST), root=str(base / "azaion")))
@pytest.fixture(scope="session")