Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] AttributeError: 'ExperimentWriter' object has no attribute 'add_figure' #1694

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
8 changes: 8 additions & 0 deletions pytorch_forecasting/models/base_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,10 @@ def log_prediction(
if not mpl_available:
return None # don't log matplotlib plots if not available

# Don't log figures if add_figure is not available
if not hasattr(self.logger.experiment, "add_figure"):
return None

for idx in log_indices:
fig = self.plot_prediction(x, out, idx=idx, add_loss_to_title=True, **kwargs)
tag = f"{self.current_stage} prediction"
Expand Down Expand Up @@ -1149,6 +1153,10 @@ def log_gradient_flow(self, named_parameters: Dict[str, torch.Tensor]) -> None:
if not mpl_available:
return None

# Don't log figures if add_figure is not available
if not hasattr(self.logger.experiment, "add_figure"):
return None

import matplotlib.pyplot as plt

fig, ax = plt.subplots()
Expand Down
4 changes: 4 additions & 0 deletions pytorch_forecasting/models/nbeats/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,10 @@ def log_interpretation(self, x, out, batch_idx):
if not mpl_available:
return None

# Don't log figures if add_figure is not available
if not hasattr(self.logger.experiment, "add_figure"):
return None

label = ["val", "train"][self.training]
if self.log_interval > 0 and batch_idx % self.log_interval == 0:
fig = self.plot_interpretation(x, out, idx=0)
Expand Down
4 changes: 4 additions & 0 deletions pytorch_forecasting/models/nhits/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,10 @@ def log_interpretation(self, x, out, batch_idx):
if not mpl_available:
return None

# Don't log figures if add_figure is not available
if not hasattr(self.logger.experiment, "add_figure"):
return None

label = ["val", "train"][self.training]
if self.log_interval > 0 and batch_idx % self.log_interval == 0:
fig = self.plot_interpretation(x, out, idx=0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,10 @@ def log_interpretation(self, outputs):
if not mpl_available:
return None

# Don't log figures if add_figure is not available
if not hasattr(self.logger.experiment, "add_figure"):
return None

import matplotlib.pyplot as plt

figs = self.plot_interpretation(interpretation) # make interpretation figures
Expand Down Expand Up @@ -857,6 +861,11 @@ def log_embeddings(self):
"""
Log embeddings to tensorboard
"""

# Don't log embeddings if add_embedding is not available
if not hasattr(self.logger.experiment, "add_embedding"):
return None

for name, emb in self.input_embeddings.items():
labels = self.hparams.embedding_labels[name]
self.logger.experiment.add_embedding(
Expand Down
Loading