matplotlib.pyplot.imshow()函数在深度学习中可视化的运用

matplotlib.pyplot.imshow()函数介绍

plt.imshow(
    X,
    cmap=None,
    norm=None,
    aspect=None,
    interpolation=None,
    alpha=None,
    vmin=None,
    vmax=None,
    origin=None,
    extent=None,
    shape=None,
    filternorm=1,
    filterrad=4.0,
    imlim=None,
    resample=None,
    url=None,
    data=None,
    **kwargs,
)

Parameters:
Xarray-like or PIL image
The image data. Supported array shapes are:

(M, N): an image with scalar data. The values are mapped to colors using normalization and a colormap. See parameters norm, cmap, vmin, vmax.

(M, N, 3): an image with RGB values (0-1 float or 0-255 int).

(M, N, 4): an image with RGBA values (0-1 float or 0-255 int), i.e. including transparency.

The first two dimensions (M, N) define the rows and columns of the image.

Out-of-range RGB(A) values are clipped.

X:
图像数据。支持的数组形状是:
(M,N) :带有标量数据的图像。数据可视化使用色彩图。
(M,N,3) :具有RGB值的图像(float或uint8)。
(M,N,4) :具有RGBA值的图像(float或uint8),即包括透明度。
前两个维度(M,N)定义了行和列图片,即图片的高和宽;

在deep learning 可视化中,经常需要可视化N×C×H×W的数据,而imshow的输入只能为(n, m) or (n, m, 3) or (n, m, 4),所以必须将N×C×H×W的数据转换,否则就会出错。

x是一个N×C×H×W的数据,将其用plt显示的代码如下
plt.imshow( (torch.cat([i for i in x], dim=-1)).permute(1, 2, 0) )
plt.show()

import matplotlib.pyplot as plt
plt.imshow(image) # 对图片image进行数据处理
plt.show() # 将图片显示出来

猜你喜欢

转载自blog.csdn.net/m0_50364811/article/details/128225394