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)))
運行上邊的代碼會報以下錯:python
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'
python
版本:3.7.4scipy
版本:1.2.1PIL
版本:6.0.0pip3 install scikit-image
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
參數。