Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions bayesflow/networks/summary_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,6 @@ def compute_metrics(self, x: Tensor, stage: str = "training", **kwargs) -> dict[

@classmethod
def from_config(cls, config, custom_objects=None):
if hasattr(cls.get_config, "_is_default") and cls.get_config._is_default:
return cls(**config)
return cls(**deserialize(config, custom_objects=custom_objects))
8 changes: 5 additions & 3 deletions bayesflow/workflows/basic_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,7 @@ def build_optimizer(self, epochs: int, num_batches: int, strategy: str) -> keras
self.optimizer = keras.optimizers.Adam(learning_rate, clipnorm=1.5)
else:
self.optimizer = keras.optimizers.AdamW(learning_rate, weight_decay=5e-3, clipnorm=1.5)
return self.optimizer

def _fit(
self,
Expand Down Expand Up @@ -955,9 +956,10 @@ def _fit(
else:
kwargs["callbacks"] = [model_checkpoint_callback]

self.build_optimizer(epochs, dataset.num_batches, strategy=strategy)

if not self.approximator.built:
# returns None if no new optimizer was built and assigned to self.optimizer, which indicates we do not have
# to (re)compile the approximator.
optimizer = self.build_optimizer(epochs, dataset.num_batches, strategy=strategy)
if optimizer is not None:
self.approximator.compile(optimizer=self.optimizer, metrics=kwargs.pop("metrics", None))

try:
Expand Down
Loading