Skip to content

Commit

Permalink
Merge pull request #38 from aertslab/warn_compile
Browse files Browse the repository at this point in the history
add warning if model not compiled
  • Loading branch information
LukasMahieu authored Oct 10, 2024
2 parents 8af84dd + bd1ba92 commit f262b2e
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/crested/tl/_crested.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,9 @@ def test(self, return_metrics: bool = False) -> dict | None:
"""
Evaluate the model on the test set.
Make sure to load a model first using Crested.load_model() before calling this function.
Make sure the model is compiled before calling this function.
Parameters
----------
return_metrics
Expand All @@ -516,10 +519,17 @@ def test(self, return_metrics: bool = False) -> dict | None:
n_test_steps = (
len(test_loader) if os.environ["KERAS_BACKEND"] == "tensorflow" else None
)

evaluation_metrics = self.model.evaluate(
test_loader.data, steps=n_test_steps, return_dict=True
)
try:
evaluation_metrics = self.model.evaluate(
test_loader.data, steps=n_test_steps, return_dict=True
)
except AttributeError as e:
logger.error(
"Something went wrong during evaluation. This is most likely caused by the model not being compiled.\n"
"Please compile the model by loading the model with compile=True or manually by using crested_object.model.compile()."
)
logger.error(e)
return None

# Log the evaluation results
for metric_name, metric_value in evaluation_metrics.items():
Expand Down

0 comments on commit f262b2e

Please sign in to comment.