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
+5 -5
View File
@@ -6,12 +6,12 @@ from dto.imageLabel import ImageLabel
from preprocessing import read_labels
from matplotlib import pyplot as plt
from constants import datasets_dir, prefix, processed_images_dir, processed_labels_dir
import constants
annotation_classes = AnnotationClass.read_json()
def visualise_dataset():
cur_dataset = os.path.join(datasets_dir, f'{prefix}2024-06-18', 'train')
cur_dataset = os.path.join(constants.config.datasets_dir, f'{constants.prefix}2024-06-18', 'train')
images_dir = os.path.join(cur_dataset, 'images')
labels_dir = os.path.join(cur_dataset, 'labels')
@@ -33,8 +33,8 @@ def visualise_dataset():
def visualise_processed_folder():
def show_image(img):
image_path = os.path.join(processed_images_dir, img)
labels_path = os.path.join(processed_labels_dir, f'{Path(img).stem}.txt')
image_path = os.path.join(constants.config.processed_images_dir, img)
labels_path = os.path.join(constants.config.processed_labels_dir, f'{Path(img).stem}.txt')
img = ImageLabel(
image_path=image_path,
image=cv2.imread(image_path),
@@ -42,7 +42,7 @@ def visualise_processed_folder():
labels=read_labels(labels_path)
)
img.visualize(annotation_classes)
images = os.listdir(processed_images_dir)
images = os.listdir(constants.config.processed_images_dir)
cur = 0
show_image(images[cur])
pass