处理 module 'scipy.misc' has no attribute 'imresize'问题

一、问题

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)
 in 
     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参数。

你可能感兴趣的:(python,scipy,tensorflow)