Visualizing and Plotting Pytorch variables

I want to visualize a python list where each element is a torch.FloatTensor variable.
Lets say that the list is stored in Dx. When I am trying the following

plt.figure()
plt.plot(Dx)

I am getting the following error:
ValueError: x and y can be no greater than 2-D, but have shapes (1200,) and (1200, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)

Can somebody please throw some light.
Or, if somebody can give me some guidance on how to plot these kinds of lists which contain error rates of a model. I just wanted an iteration wise plot.

You need to do two things: remove the superfluous dimensions from the y argument to plt.plot and convert your tensors to numpy, like so:

In [1]: import torch

In [2]: import matplotlib.pyplot as plt

In [3]: x = torch.ones(1200)

In [4]: y = torch.ones(1200, 1, 1, 1, 1, )

In [5]: x.size()
Out[5]: torch.Size([1200])

In [6]: y.size()
Out[6]: torch.Size([1200, 1, 1, 1, 1])

In [7]: y.squeeze().size()
Out[7]: torch.Size([1200])

In [8]: plt.plot(x.numpy(), y.squeeze().numpy())
1 Like

Thanks a Lot.
It Worked.