Add metric name validation for hyperparameter search (#241)
This commit is contained in:
1 parent
c4940edaec
commit
15bef37b1d
2 files changed
+8
-1
No files matched your search
@@ -7,6 +7,7 @@ defaults:
|
|||||||
- override /hydra/sweeper: optuna
|
- override /hydra/sweeper: optuna
|
||||||
|
|
||||||
# choose metric which will be optimized by Optuna
|
# choose metric which will be optimized by Optuna
|
||||||
|
# make sure this is the correct name of some metric logged in lightning module!
|
||||||
optimized_metric: "val/acc_best"
|
optimized_metric: "val/acc_best"
|
||||||
|
|
||||||
hydra:
|
hydra:
|
||||||
|
|||||||
+7
-1
@@ -77,7 +77,13 @@ def train(config: DictConfig) -> Optional[float]:
|
|||||||
trainer.fit(model=model, datamodule=datamodule)
|
trainer.fit(model=model, datamodule=datamodule)
|
||||||
|
|
||||||
# Get metric score for hyperparameter optimization
|
# Get metric score for hyperparameter optimization
|
||||||
score = trainer.callback_metrics.get(config.get("optimized_metric"))
|
optimized_metric = config.get("optimized_metric")
|
||||||
|
if optimized_metric and optimized_metric not in trainer.callback_metrics:
|
||||||
|
raise Exception(
|
||||||
|
"Metric for hyperparameter optimization not found! "
|
||||||
|
"Make sure the `optimized_metric` in `hparams_search` config is correct!"
|
||||||
|
)
|
||||||
|
score = trainer.callback_metrics.get(optimized_metric)
|
||||||
|
|
||||||
# Test the model
|
# Test the model
|
||||||
if config.get("test_after_training") and not config.trainer.get("fast_dev_run"):
|
if config.get("test_after_training") and not config.trainer.get("fast_dev_run"):
|
||||||
|
|||||||
Reference in new issue
Block a user