Skip to content

Commit 9722282

Browse files
Potential fix for pull request finding
in plot_image, detach if it's a torch tensor Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent 707622a commit 9722282

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

pyvisim/_utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ def plot_image(image: np.ndarray | torch.Tensor, title: str = "Image") -> None:
4343
"""
4444
plt.figure(figsize=(10, 10))
4545
if isinstance(image, torch.Tensor):
46-
image = image.permute(1, 2, 0)
46+
image = image.detach().cpu()
47+
if image.ndim == 3:
48+
image = image.permute(1, 2, 0)
49+
image = image.numpy()
4750
plt.imshow(image)
4851
plt.axis("off")
4952
plt.title(title)

0 commit comments

Comments
 (0)