def tensor2img(x):
array = np.array(x)
if x.ndim == 4:
imgs = [array[i] for i in range(array.shape[0])]
else:
raise ValueError(“没有批次维度”)
for item in imgs:
img = np.transpose(item,(1,2,0))*256 # 转置去适应格式
img = img.astype(np.int)
plt.imshow(img)
plt.show()
Python--张量转化为PIL格式
最新推荐文章于 2023-10-07 11:30:50 发布