MCPcopy Create free account
hub / github.com/BioinfoMachineLearning/FlowDock / get_metric_value

Function get_metric_value

flowdock/utils/utils.py:101–122  ·  view source on GitHub ↗

Safely retrieves value of the metric logged in LightningModule. :param metric_dict: A dict containing metric values. :param metric_name: If provided, the name of the metric to retrieve. :return: If a metric name was provided, the value of the metric.

(metric_dict: Dict[str, Any], metric_name: Optional[str])

Source from the content-addressed store, hash-verified

99
100
101def get_metric_value(metric_dict: Dict[str, Any], metric_name: Optional[str]) -> Optional[float]:
102 """Safely retrieves value of the metric logged in LightningModule.
103
104 :param metric_dict: A dict containing metric values.
105 :param metric_name: If provided, the name of the metric to retrieve.
106 :return: If a metric name was provided, the value of the metric.
107 """
108 if not metric_name:
109 log.info("Metric name is None! Skipping metric value retrieval...")
110 return None
111
112 if metric_name not in metric_dict:
113 raise Exception(
114 f"Metric value not found! <metric_name={metric_name}>\n"
115 "Make sure metric name logged in LightningModule is correct!\n"
116 "Make sure `optimized_metric` name in `hparams_search` config is correct!"
117 )
118
119 metric_value = metric_dict[metric_name].item()
120 log.info(f"Retrieved metric value! <{metric_name}={metric_value}>")
121
122 return metric_value
123
124
125def read_strings_from_txt(path: str) -> List[str]:

Callers 1

mainFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected