diff --git a/src/super_gradients/training/sg_trainer/sg_trainer.py b/src/super_gradients/training/sg_trainer/sg_trainer.py index c04df5db63..a6017c646e 100755 --- a/src/super_gradients/training/sg_trainer/sg_trainer.py +++ b/src/super_gradients/training/sg_trainer/sg_trainer.py @@ -557,11 +557,15 @@ def _init_monitored_items(self): # make sure the metric_to_watch is an exact match metric_titles = self.loss_logging_items_names + get_metrics_titles(self.valid_metrics) - metric_to_watch_idx = fuzzy_idx_in_list(self.metric_to_watch, metric_titles) + try: + metric_to_watch_idx = fuzzy_idx_in_list(self.metric_to_watch, metric_titles) + except IndexError: + raise ValueError(f"No match found for `metric_to_watch={self.metric_to_watch}`. Available metrics to monitor are: `{metric_titles}`.") + metric_to_watch = metric_titles[metric_to_watch_idx] if metric_to_watch != self.metric_to_watch: logger.warning( - f"No exact match found for `metric_to_watch={self.metric_to_watch}`. It should be one of {metric_titles}. \n" + f"No exact match found for `metric_to_watch={self.metric_to_watch}`. Available metrics to monitor are: `{metric_titles}`. \n" f"`metric_to_watch={metric_to_watch} will be used instead.`" ) self.metric_to_watch = metric_to_watch diff --git a/src/super_gradients/training/utils/utils.py b/src/super_gradients/training/utils/utils.py index 3de562e43c..48f7545227 100755 --- a/src/super_gradients/training/utils/utils.py +++ b/src/super_gradients/training/utils/utils.py @@ -291,7 +291,12 @@ def fuzzy_idx_in_list(name: str, lst: List[str]) -> int: :param lst: List[str], the list as described above. :return: int, index of name in lst in the matter discussed above. """ - return [fuzzy_str(x) for x in lst].index(fuzzy_str(name)) + fuzzy_name = fuzzy_str(name) + fuzzy_list = [fuzzy_str(x) for x in lst] + if fuzzy_name in fuzzy_list: + return fuzzy_list.index(fuzzy_name) + else: + raise IndexError(f"Value `{name}` not found in the list `{lst}`. Please check the spelling.") def get_param(params, name, default_val=None):