Builds and returns a trainer based on the config. Args: config (dict): the config dict (typically constructed using utils.config.get_config) config.trainer (str): the name of the trainer to use. The module named "{config.trainer}_trainer" must exist in trainers root module
(config)
| 26 | |
| 27 | |
| 28 | def get_trainer(config): |
| 29 | """Builds and returns a trainer based on the config. |
| 30 | |
| 31 | Args: |
| 32 | config (dict): the config dict (typically constructed using utils.config.get_config) |
| 33 | config.trainer (str): the name of the trainer to use. The module named "{config.trainer}_trainer" must exist in trainers root module |
| 34 | |
| 35 | Raises: |
| 36 | ValueError: If the specified trainer does not exist under trainers/ folder |
| 37 | |
| 38 | Returns: |
| 39 | Trainer (inherited from zoedepth.trainers.BaseTrainer): The Trainer object |
| 40 | """ |
| 41 | assert "trainer" in config and config.trainer is not None and config.trainer != '', "Trainer not specified. Config: {0}".format( |
| 42 | config) |
| 43 | try: |
| 44 | Trainer = getattr(import_module( |
| 45 | f"zoedepth.trainers.{config.trainer}_trainer"), 'Trainer') |
| 46 | except ModuleNotFoundError as e: |
| 47 | raise ValueError(f"Trainer {config.trainer}_trainer not found.") from e |
| 48 | return Trainer |
nothing calls this directly
no outgoing calls
no test coverage detected