"""Evaluate a trained model with dataset specified in config.toml file."""from__future__importannotationsimportloggingimportpathlibfrom..importconfigfrom..importevalaseval_modulefrom..common.loggingimportconfig_logging_for_cli,log_versionlogger=logging.getLogger(__name__)
[docs]defeval(toml_path:str|pathlib.Path)->None:"""Evaluate a trained model with dataset specified in config.toml file. Function called by command-line interface. Parameters ---------- toml_path : str, Path path to a configuration file in TOML format. Returns ------- None """toml_path=pathlib.Path(toml_path)cfg=config.Config.from_toml_path(toml_path)ifcfg.evalisNone:raiseValueError(f"eval called with a config.toml file that does not have a EVAL section: {toml_path}")# ---- set up logging ---------------------------------------------------------------------------------------------config_logging_for_cli(log_dst=cfg.eval.output_dir,log_stem="eval",level="INFO",force=True)log_version(logger)logger.info("Logging results to {}".format(cfg.eval.output_dir))ifcfg.eval.dataset.pathisNone:raiseValueError("No value is specified for 'dataset_path' in this .toml config file."f"To generate a .csv file that represents the dataset, "f"please run the following command:\n'vak prep {toml_path}'")eval_module.eval(model_config=cfg.eval.model.asdict(),dataset_config=cfg.eval.dataset.asdict(),checkpoint_path=cfg.eval.checkpoint_path,labelmap_path=cfg.eval.labelmap_path,output_dir=cfg.eval.output_dir,num_workers=cfg.eval.num_workers,batch_size=cfg.eval.batch_size,spect_scaler_path=cfg.eval.spect_scaler_path,device=cfg.eval.device,post_tfm_kwargs=cfg.eval.post_tfm_kwargs,)