Plotting intermediate data tensors - access data or detach?


I’m still confused with detach(), altough i searched and read a lot… When I’m plotting tensors in each epoch, like input images or decode one hot encoded output images and plot them, is it correct to access this tensors by .data.cpu() or do I need .detach().cpu() ? Im running my model on a gpu, it is basically a VAE.

1st example:

self.create_output_image_grids(img_data.detach().cpu(), recon_data.detach().cpu())

In this function I basically use to create a grid of images…

2nd example
If I keep track of latent var’s (mu, logvar) to make some plots e.g. every 5 epochs:

recon_data, mu, logvar, z = model(img_data)

Big thanks in advance!

It is the same, though it has been suggested that .data is internal/private, it is used too often to break it.