解决:AttributeError: module ‘scipy.misc’ has no attribute ‘imresize’


解决:AttributeError: module ‘scipy.misc’ has no attribute ‘imresize’





背景

在使用之前的代码时,报错:
Traceback (most recent call last):
File “xxx”, line xx, in
misc.imresize(cropped_temp, (image_size, image_size), interp=‘bilinear’)
AttributeError: module ‘scipy.misc’ has no attribute ‘imresize’



报错问题


Traceback (most recent call last):
  File "xxx", line xx, in <module>
    misc.imresize(cropped_temp, (image_size, image_size), interp='bilinear')
AttributeError: module 'scipy.misc' has no attribute 'imresize'


报错翻译

主要报错信息内容翻译如下所示:


Traceback (most recent call last):
  File "xxx", line xx, in <module>
    misc.imresize(cropped_temp, (image_size, image_size), interp='bilinear')
AttributeError: module 'scipy.misc' has no attribute 'imresize'

翻译:

追溯(最近一次通话):
文件“xxx”,第xx行,在中
misc.imresize(cropped_temp,(image_size,image_size),interp=“双线性”)
AttributeError:模块“scipy.misc”没有属性“imresize”



报错位置代码

from scipy import misc
misc.imresize(cropped_temp, (image_size, image_size), interp='bilinear')


报错原因

经过查阅资料,发现这个错误产生的原因是scipy模块1.20版本之后该方法已经被弃用了,如果继续使用这个方法,就会报这样的错误。

小伙伴们按下面的解决方法即可解决!!!



解决方法

要解决这个错误,需要这里总结了以下几个解决办法:

方法一 scipy版本回退(不推荐)

回退到scipy模块1.20之前的版本,版本回退的pip指令如下:

pip install scipy==1.2.1 -i https://pypi.tuna.tsinghua.edu.cn/simple

注意:因为版本回退后会造成该模块与环境中的tensorflow包或者其他包的不兼容,后续还得再更新回来,或者是单独建一个环境,比较麻烦。

方法二 使用skimage保存图片即可(推荐)

skimage的方法正确的代码是:

from skimage.transform import resize
scaled_temp = resize(cropped_temp,output_shape=(image_size, image_size))


今天的分享就到此结束了

欢迎点赞评论关注三连

在这里插入图片描述

  • 11
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ninghes

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值