2017-12-27 427 views
1

這是我的Python代碼:錯誤試圖分裂圖像顏色:numpy.ndarray」對象有沒有屬性‘面具’

from PIL import Image 

labels = ['airplane','automobile','bird','cat','deer','dog','frog','horse','ship','truck'] 

from keras.datasets import cifar10 

(X_train, Y_train), (X_test,y_test) = cifar10.load_data() 



index = int(input('Enter an image index: ')) 
display_image = X_train[index] 
display_label = Y_train[index][0] 

from matplotlib import pyplot as plt 

red_image = Image.fromarray(display_image) 
red,green,blue = red_image.split() 

plt.imshow(red, cmap="Reds") 
plt.show() 

print(labels[display_label]) 

那是錯誤返回

File "/Users/mcarvalho/PycharmProjects/SimpleImageRecognition/venv/lib/python3.6/site-packages/matplotlib/image.py", line 419, in _make_image if A.mask.shape == A.shape: AttributeError: 'numpy.ndarray' object has no attribute 'mask'

+0

更新numpy和matplot lib到最新版本後,我有同樣的問題。不過,不知道那裏會發生什麼...... – Dmytro

回答

1

確實存在一個bug在matplotlib中。你可以將你的matplotlib降級到版本2.0.0,然後它會工作。至少它適合我。降級matplotlib你必須運行

pip install --upgrade --force-reinstall matplotlib==2.0.0 

希望它會幫助你!

相關問題