处理-module-scipymisc-has-no-attribute-imresize问题

6次阅读

共计 1049 个字符,预计需要花费 3 分钟才能阅读完成。

一、问题

import scipy
from PIL import Image
from scipy import ndimage
# import scipy.misc
# from scipy.misc import imresize

my_image = "thumbs_up.jpg"

fname = "images/" + my_image
image = np.array(plt.imread(fname))
#Image.fromarray(arr).resize()
my_image = scipy.misc.imresize(image, size=(64, 64)).reshape((1, 64 * 64 * 3)).T
my_image_prediction = predict(my_image, parameters)

plt.imshow(image)
print("Your algorithm predicts: y =" + str(np.squeeze(my_image_prediction)))

运行上边的代码会报如下错:

AttributeErrorTraceback (most recent call last)
<ipython-input-25-824eb639aa80> in <module>
     10 image = np.array(plt.imread(fname))
     11 #Image.fromarray(arr).resize()
---> 12 my_image = scipy.misc.imresize(image, size=(64, 64)).reshape((1, 64 * 64 * 3)).T
     13 my_image_prediction = predict(my_image, parameters)
     14 

AttributeError: module 'scipy.misc' has no attribute 'imresize'

环境

  • 1、python版本:3.7.4
  • 2、scipy版本:1.2.1
  • 3、PIL版本:6.0.0

二、解决方案

1、安装 scikit-image

pip3 install scikit-image

2、调用 resize()

from skimage.transform import resize
my_image = resize(image, output_shape=(64, 64)).reshape((1, 64 * 64 * 3)).T

注意 :这里的resize() 的参数与较老版本的 scipy.misc 中的 imresize() 有所不同,前者的 output_shape 参数对应后者的 size 参数。

正文完
 0