logo资料库

无需降级scipy的情况下解决AttributeError: module ‘scipy.misc’ has no attrib....pdf

第1页 / 共2页
第2页 / 共2页
资料共2页,全文预览结束
的情况下解决AttributeError: module 无需降级scipy的情况下解决 无需降级 ‘scipy.misc’ has no attribute ‘imread’,,imresize,,imsave 等问题等问题 无需降级scipy的情况下解决AttributeError: module ‘scipy.misc’ has no attribute ‘imread’, AttributeError: module ‘scipy.misc’ has no attribute ‘imresize’, AttributeError:module ‘scipy.misc’ has no attribute ‘imsave’问题 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’。 原因是scipy在新版本中misc库中弃用了一部函数,其中就包括imread,imresize和imsave。 在很多回答中都提到了降低scipy的版本,但是觉得这种解决方法很不爽,官方弃用这些函数肯定有他的道理,不能遇到问题 就总想着降版本。 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 img = misc.imread(image_path) AttributeError: module 'scipy.misc' has no attribute 'imread' 修改如下 修改如下 import imageio img = imageio.imread(image_path) 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 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)) 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 misc.imsave(output_filename, scaled_temp) AttributeError: module 'scipy.misc' has no attribute 'imsave'
修改如下 修改如下 import imageio imageio.imwrite(output_filename,scaled_temp) 那么问题是scipy在新版本的misc库中为什么要弃用这些函数呢呢,我也不知道, 这个misc是miscellaneous缩写(杂项的意思) Miscellaneous routines (scipy.misc) Various utilities that don’t have another home. 意思就是不知道放哪的函数都放这里了。 我们可以看到很多和cv相关的函数都被弃用了 我猜大概可能是因为想要使用这些函数必须安装Python Imaging Library(PIL)库才可以,scipy的开发者觉得这不符合他们性 格,可能就给弃用了… 以后直接使用imageio库下的函数就可以了 imageio的API 作者:秋名山怎么走阿
分享到:
收藏