Plot and Images not logged with WandbLogger outside LightningModule

Hi all,

I am using pytorch_lightning.loggers.WandbLogger to log some intermediate results of my preprocessing but nothing (i.e. matplotlib plots and images) are logged, except the key name.

Below is what I did:

wandb_logger = WandbLogger(..)
runner = Trainer(logger=wandb_logger,..)
data = VAEDataset(.., logger=runner.logger,..) # LightningDataModule
data.setup()

# in my dataset (after some transforms are performed)
plt.figure(figsize=(10, 30))
plt.subplot(131), plt.imshow(orig_spec.detach(), cmap='gray')
plt.title('Input'), plt.xticks([]), plt.yticks([])
plt.subplot(132), plt.imshow(filtered_spec.squeeze().detach(), cmap='gray')
plt.title('FilteredSpec'), plt.xticks([]), plt.yticks([])
plt.subplot(133), plt.imshow(magnitude_spec.detach(), cmap='gray')
plt.title('MagnitudeSpec'), plt.xticks([]), plt.yticks([])
self.logger.experiment.log(
        {"HPFilter/Input_Filtered-_Magnitude-Spec": plt}
        )

There is no subdir called “HPFilter” under “media” but when I checked wandb-summary.json:

..., "HPFilter/FilteredSpec": {"_type": "image-file", "sha256": "92bd05772ad44d6be9ef9fed80df00ff649e378abbcbb34f73d4082aceacedb0", "size": 86404, "path": "media/images/HPFilter/FilteredSpec_2_92bd05772ad44d6be9ef.png", "format": "png", "width": 128, "height": 256, "caption": "FilteredSpec_33150.png"}, ...

Is the problem that such logging could only be performed within LightningModule?

Many thanks in advance for any hints!

Added:
To eliminate that the problem lies in my actual data, I tried the below to replace my intended logging:

    arr = torch.rand(256, 128)
        wandb.log(
            {"HPFilter/FilteredSpec": wandb.Image(torch.flipud(arr).detach().cpu().numpy(), caption=f"FilteredSpec.png")}
        )

It still behaved the same.

Hi,

I solved this problem over the weekend.

@JXuann can you share what was required to fix the issue? Thanks!