aboutsummaryrefslogtreecommitdiff
path: root/src/utils.py
diff options
context:
space:
mode:
authorgdamms <damguillotin@gmail.com>2026-02-05 19:55:58 +0100
committergdamms <damguillotin@gmail.com>2026-02-05 19:55:58 +0100
commitf1be02af8c33d4136ad7c90dd43158a8ff6e5af1 (patch)
tree3d7facac2732046ce1447156afe7dacc3b64d585 /src/utils.py
parenta5d5f30fbd9c6c7c78834072401932c84bddaf14 (diff)
downloaddiffusion-mnist-f1be02af8c33d4136ad7c90dd43158a8ff6e5af1.tar.gz
diffusion-mnist-f1be02af8c33d4136ad7c90dd43158a8ff6e5af1.zip
better plots, semi working autoencoder
Diffstat (limited to 'src/utils.py')
-rw-r--r--src/utils.py20
1 files changed, 10 insertions, 10 deletions
diff --git a/src/utils.py b/src/utils.py
index f727a68..f34ec33 100644
--- a/src/utils.py
+++ b/src/utils.py
@@ -6,9 +6,9 @@ import os
import io
import numpy as np
import torch
-import scipy.linalg
from PIL import Image
-import matplotlib.pyplot as plt
+import plotly.graph_objects as go
+from plotly.subplots import make_subplots
from .config import CHECKPOINT_DIR, PLOTS_DIR
@@ -51,18 +51,18 @@ def tensor_to_images(tensor: torch.Tensor) -> np.ndarray:
return img
-def figure_to_image(figure: plt.Figure) -> np.ndarray:
+def figure_to_image(figure: go.Figure) -> np.ndarray:
"""
- Convert a matplotlib figure to a numpy image array.
+ Convert a plotly figure to a numpy image array.
Args:
- figure: Matplotlib figure
+ figure: Plotly figure
Returns:
Numpy array of the figure image
"""
buf = io.BytesIO()
- figure.savefig(buf, format='png')
+ figure.write_image(buf, format='png')
buf.seek(0)
image = np.array(Image.open(buf))
return image
@@ -97,14 +97,14 @@ def load_checkpoint(model: torch.nn.Module, filename: str) -> torch.nn.Module:
return model
-def save_plot(figure: plt.Figure, filename: str):
+def save_plot(figure: go.Figure, filename: str):
"""
- Save a matplotlib figure to the plots directory.
+ Save a plotly figure to the plots directory.
Args:
- figure: Matplotlib figure to save
+ figure: Plotly figure to save
filename: Filename (will be saved in PLOTS_DIR)
"""
ensure_dirs()
path = os.path.join(PLOTS_DIR, filename)
- figure.savefig(path)
+ figure.write_image(path)