mirror of
https://github.com/azaion/ai-training.git
synced 2026-04-22 19:56:36 +00:00
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:
@@ -56,8 +56,8 @@ def _prepare_form_dataset(
|
||||
constants_patch(tmp_path)
|
||||
import train
|
||||
|
||||
proc_img = Path(c_mod.processed_images_dir)
|
||||
proc_lbl = Path(c_mod.processed_labels_dir)
|
||||
proc_img = Path(c_mod.config.processed_images_dir)
|
||||
proc_lbl = Path(c_mod.config.processed_labels_dir)
|
||||
proc_img.mkdir(parents=True, exist_ok=True)
|
||||
proc_lbl.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
@@ -70,14 +70,8 @@ def _prepare_form_dataset(
|
||||
if stem in corrupt_stems:
|
||||
dst.write_text("0 1.5 0.5 0.1 0.1\n", encoding="utf-8")
|
||||
|
||||
today_ds = osp.join(c_mod.datasets_dir, train.today_folder)
|
||||
monkeypatch.setattr(train, "today_dataset", today_ds)
|
||||
monkeypatch.setattr(train, "processed_images_dir", c_mod.processed_images_dir)
|
||||
monkeypatch.setattr(train, "processed_labels_dir", c_mod.processed_labels_dir)
|
||||
monkeypatch.setattr(train, "corrupted_images_dir", c_mod.corrupted_images_dir)
|
||||
monkeypatch.setattr(train, "corrupted_labels_dir", c_mod.corrupted_labels_dir)
|
||||
monkeypatch.setattr(train, "datasets_dir", c_mod.datasets_dir)
|
||||
return train
|
||||
today_ds = osp.join(c_mod.config.datasets_dir, train.today_folder)
|
||||
return train, today_ds
|
||||
|
||||
|
||||
@pytest.mark.performance
|
||||
@@ -88,7 +82,7 @@ def test_pt_dsf_01_dataset_formation_under_thirty_seconds(
|
||||
fixture_images_dir,
|
||||
fixture_labels_dir,
|
||||
):
|
||||
train = _prepare_form_dataset(
|
||||
train, today_ds = _prepare_form_dataset(
|
||||
monkeypatch,
|
||||
tmp_path,
|
||||
constants_patch,
|
||||
|
||||
Reference in New Issue
Block a user