scipy1.3.0開始被棄用的imread,imresize,如何代替
SciPy最新官方文檔的說明(20190730):
Functions from scipy.interpolate (spleval, spline, splmake, and spltopp) and functions from scipy.misc (bytescale, fromimage, imfilter, imread, imresize, imrotate, imsave, imshow, toimage) have been removed. The former set has been deprecated since v0.19.0 and the latter has been deprecated since v1.0.0. Similarly, aliases from scipy.misc (comb, factorial, factorial2, factorialk, logsumexp, pade, info, source, who) which have been deprecated since v1.0.0 are removed. SciPy documentation for v1.1.0 can be used to track the new import locations for the relocated functions.
文檔中說明了在scipy的0.19.0版本和1.0.0版本中可以用到的imread,imresize函數在scipy的1.3.0版本中全部被遺棄。
如果在最新版scipy中繼續使用這兩個函數,會出現如下報錯:
AttributeError: module 'scipy.misc' has no attribute 'imread'
AttributeError: module 'scipy.misc' has no attribute 'imresize'
然而網上大多數對這個問題的解決辦法都是pip安裝PIL或者pillow,
這並不能解決到實際問題(因為scipy已經不支持這兩個函數,pillow依賴庫的安裝與否不是根本問題)
下面給出這個兩個函數的代替方案:
1. imread
先前版本
img = scipy.misc.imread(myImage)
新版本
import imageio
img = imageio.imread(myImage)
2. imresize
先前版本
img = scipy.misc.imresize(myImage, size=(num_px,num_px))