Tensorboard 图像出错: scipy.misc.toimage 已过时

作者: ghost创建于 2019年12月4日更新于 2021年12月10日

使用最新版本的 scipy.misc 后, scipy.misc.toimage 不再可用。要加载和保存为 png 格式的图像,我们现在必须使用 PIL,这会打破 tensorboard 图像摘要。以下是我修复此 bug 的方法: 1./ 在 main.py 的末尾,记录一个 uint8 图像 logger.image_summary(tag, (images * 255).astype(np.uint8), step+1) 2./ 在 Logger 类中,使用 PIL 库将图像封装为字节(模式为"L",读取图像为 B&W uint8 图像) from PIL import Image Image.fromarray(img, mode='L').save(s, "PNG") [编辑] 我不习惯对其他人的代码进行贡献,但如果您教我如何做,我可以自己修复此 bug :)

内容来源: yunjey/pytorch-tutorial