Code using omegaconf
to handle IO.
IO
source
class_to_str
class_to_str (cls)
source
load_config
load_config (file_path)
source
config_to_dict
config_to_dict (config)
source
save_dataclass_yaml
save_dataclass_yaml (data_obj, file_path)
source
save_dict_yaml
save_dict_yaml (dict_obj, file_path)
Test
@dataclass
class MyConfig:
target:str = class_to_str(OmegaConf)
clr_dim: int = 80
features: list[int]=None
c = MyConfig()
c.features = [1,2,3]
OmegaConf.structured(c)
{'target': 'omegaconf.omegaconf.OmegaConf', 'clr_dim': 80, 'features': [1, 2, 3]}
Object config load
Adapted from: https://github.com/Stability-AI/generative-models
source
get_obj_from_str
get_obj_from_str (string, reload=False, invalidate_cache=True)
source
instantiate_from_config
instantiate_from_config (config)
store_model_state_dict
store_model_state_dict (state_dict, save_path)
source
load_model_state_dict
load_model_state_dict (save_path, device)
Tensors and numpy
torch.serialization.DEFAULT_PROTOCOL
source
store_tensor
store_tensor (tensor, save_path, type='tensor')
source
load_tensor
load_tensor (save_path, device, type='tensor')
Back to top