'AttributeError: module 'scipy.misc' has no attribute 'toimage' 2
This is my code:
for i, img in enumerate(images):
# Write the image to a string
try:
s = StringIO()
except:
s = BytesIO()
scipy.misc.toimage(img).save(s, format="png")
This is the error traceback:
Traceback (most recent call last):
File "C:/Users/tkdgu/OneDrive/바탕 화면/CycleGAN-master/CycleGAN-master/CycleGAN_train.py", line 275, in <module>
img_logger.image_summary(tag, images, epoch + 1)
File "C:\Users\tkdgu\OneDrive\바탕 화면\CycleGAN-master\CycleGAN-master\logger.py", line 34, in image_summary
scipy.misc.toimage(img).save(s, format="png")
AttributeError: module 'scipy.misc' has no attribute 'toimage'
I can't install scipy 1.1.0 or 1.2.0.
I want to change scipy.misc.toimage(img).save(s, format="png").
Solution 1:[1]
The recommended method here is to use PIL.Image.fromarray
So, assuming your images is an iterable of numpy arrays, will save each image as a file, check PIL.Image.save documentation for more options
from PIL import Image
for i, img in enumerate(images):
# This will save to the disk
Image.fromarray(img).save(f'img_{i:06d}.png', 'png')
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Bob |
