尝试分割图像颜色时出错:numpy.ndarray'对象没有属性'mask'

Mau*_*lho 3 matplotlib image-recognition keras tensorflow

这是我的Python代码:

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])
Run Code Online (Sandbox Code Playgroud)

这就是返回的错误

文件“/Users/mcarvalho/PycharmProjects/SimpleImageRecognition/venv/lib/python3.6/site-packages/matplotlib/image.py”,第 419 行,在 _make_image 中,如果 A.mask.shape == A.shape: AttributeError: ' numpy.ndarray'对象没有属性'mask'

小智 5

似乎在 matplotlib 2.2.2 中也得到了修复:

sudo pip3 install matplotlib --upgrade
Run Code Online (Sandbox Code Playgroud)