无需降级scipy,解决AttributeError: module ‘scipy.misc’ has no attribute ‘imread’,imresize,imsave问题
1. 问题最近遇到如下三个错误(imread,imresize,imsave)AttributeError: module ‘scipy.misc’ has no attribute ‘imread’,AttributeError: module ‘scipy.misc’ has no attribute ‘imresize’,AttributeError:module ‘scipy.misc’
1. 问题
最近遇到如下三个错误(imread,imresize,imsave)
AttributeError: module ‘scipy.misc’ has no attribute ‘imread’,
AttributeError: module ‘scipy.misc’ has no attribute ‘imresize’,
AttributeError:module ‘scipy.misc’ has no attribute ‘imsave’。
在很多回答中都提到了 降 低 s c i p y 的 版 本 \color{red}降低scipy的版本 降低scipy的版本,官方弃用这些函数肯定有他的道理,不能遇到问题就总想着降版本。
1.1 原因
- scipy在新版本的misc库中弃用这些函数。(misc是miscellaneous缩写(杂项的意思))
2. 问题解决
2.1 'imread’的解决方法
对于AttributeError: module ‘scipy.misc’ has no attribute 'imread’
的解决方法
- 代码如下:
from scipy import misc img = misc.imread(image_path)
- 错误如下:
Traceback (most recent call last): File "Make_aligndata_git.py", line 57, in <module> img = misc.imread(image_path) AttributeError: module 'scipy.misc' has no attribute 'imread'
- 修改如下:
import imageio img = imageio.imread(image_path)
2.2 'imresize’的解决方法
对于AttributeError: module ‘scipy.misc’ has no attribute 'imresize’
的解决方法
- 代码如下:
from scipy import misc scaled_temp = misc.imresize(cropped_temp, (image_size, image_size), interp='bilinear')
- 错误如下:
Traceback (most recent call last): File "Make_aligndata_git.py", line 98, in <module> scaled_temp = misc.imresize(cropped_temp, (image_size, image_size), interp='bilinear') AttributeError: module 'scipy.misc' has no attribute 'imresize'
- 修改如下:
from skimage.transform import resize scaled_temp = resize(cropped_temp,output_shape=(image_size, image_size))
2.3 'imread’的解决方法
对于AttributeError: module ‘scipy.misc’ has no attribute 'imread’
的解决方法
- 代码如下:
from scipy import misc misc.imsave(output_filename, scaled_temp)
- 错误如下:
Traceback (most recent call last): File "Make_aligndata_git.py", line 104, in <module> misc.imsave(output_filename, scaled_temp) AttributeError: module 'scipy.misc' has no attribute 'imsave'
- 修改如下:
import imageio imageio.imwrite(output_filename,scaled_temp)
更多推荐
所有评论(0)