import yaml | |
import os | |
import glob | |
CONFIG_DIR = "./BeamDiffusionModel/models/diffusionModel/configs" # Directory containing config files | |
def load_all_configs(): | |
config = {} # Start with an empty config | |
# Find all YAML files in the directory (sorted for consistency) | |
config_files = sorted(glob.glob(os.path.join(CONFIG_DIR, "*.yml"))) | |
for file_path in config_files: | |
with open(file_path, "r") as file: | |
new_config = yaml.safe_load(file) or {} # Load config (avoid None) | |
config = deep_merge(config, new_config) # Merge into main config | |
return config | |
def deep_merge(dict1, dict2): | |
"""Recursively merges two dictionaries (deep merge).""" | |
for key, value in dict2.items(): | |
if isinstance(value, dict) and key in dict1 and isinstance(dict1[key], dict): | |
dict1[key] = deep_merge(dict1[key], value) # Recursively merge | |
else: | |
dict1[key] = value # Overwrite | |
return dict1 | |
# Load and merge all configs automatically | |
CONFIG = load_all_configs() | |
print(os.getcwd()) | |
print("Final Merged Config:") | |
print(CONFIG) # Display merged config | |