如何将返回的viz.visualize_image_attr保存为图像Python

c0vxltue  于 2023-02-18  发布在  Python
关注(0)|答案(1)|浏览(158)

我需要使用的返回值

viz.visualize_image_attr(fa_attr_without_max[0].cpu().detach().permute(1, 2, 0).numpy(), sign="all", title="Integrated Gradients")

作为图像。
此方法返回:2-element tuple of *figure, **axis*;它们的数据类型为matplotlib.pyplot.figure
我尝试了plt并搜索了将元组转换为图像,但没有找到结果

cngwdvgl

cngwdvgl1#

您应该能够使用matplotlib.pyplot.savefig

from matplotlib import pyplot as plt

example = (x, y) #Assume these are matplotlib figures returned from your func
example[0].savefig('foo.png')
example[1].savefig('foo2.pdf')

相关问题