Builds a model from a config. The model is specified by the model name and version in the config. The model is then constructed using the build_from_config function of the model interface. This function should be used to construct models for training and evaluation. Args: config (di
(config)
| 26 | from dzoedepth.models.depth_model import DepthModel |
| 27 | |
| 28 | def build_model(config) -> DepthModel: |
| 29 | """Builds a model from a config. The model is specified by the model name and version in the config. The model is then constructed using the build_from_config function of the model interface. |
| 30 | This function should be used to construct models for training and evaluation. |
| 31 | |
| 32 | Args: |
| 33 | config (dict): Config dict. Config is constructed in utils/config.py. Each model has its own config file(s) saved in its root model folder. |
| 34 | |
| 35 | Returns: |
| 36 | torch.nn.Module: Model corresponding to name and version as specified in config |
| 37 | """ |
| 38 | module_name = f"dzoedepth.models.{config.model}" |
| 39 | try: |
| 40 | module = import_module(module_name) |
| 41 | except ModuleNotFoundError as e: |
| 42 | # print the original error message |
| 43 | print(e) |
| 44 | raise ValueError( |
| 45 | f"Model {config.model} not found. Refer above error for details.") from e |
| 46 | try: |
| 47 | get_version = getattr(module, "get_version") |
| 48 | except AttributeError as e: |
| 49 | raise ValueError( |
| 50 | f"Model {config.model} has no get_version function.") from e |
| 51 | return get_version(config.version_name).build_from_config(config) |
no test coverage detected