gpt4 book ai didi

python - 如何在 PyTorch 中显示单个图像?

转载 作者:太空狗 更新时间:2023-10-30 00:22:38 24 4
gpt4 key购买 nike

如何显示形状为 (3, 224, 224) 的 PyTorch Tensor 表示 224x224 RGB 图像?使用 plt.imshow(image) 给出错误:

TypeError: Invalid dimensions for image data

最佳答案

给定一个表示图像的Tensor,使用.permute()将 channel 作为最后一个维度:

plt.imshow(  tensor_image.permute(1, 2, 0)  )

备注:permute does not copy or allocate memory , 和 from_numpy() doesn't either.

关于python - 如何在 PyTorch 中显示单个图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53623472/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com