Original Code:
# Load And Plot Sample CIFAR-10 Images
# Plot ad hoc CIFAR-10 instances
from keras.datasets import cifar10
from matplotlib import pyplot
from scipy.misc import toimage
# load data
(X_train, y_train),(X_test, y_test) = cifar10.load_data()
# create a grid of 3 x 3 images
for i in range(0, 9):
pyplot.subplot(330 + 1 + i)
pyplot.imshow(toimage(X_train[i]))
# show the plot
pyplot.show()
Modified Code:
# Load And Plot Sample CIFAR-10 Images
# Plot ad hoc CIFAR-10 instances
from keras.datasets import cifar10
from matplotlib import pyplot
from PIL import Image
# load data
(X_train, y_train),(X_test, y_test) = cifar10.load_data()
# create a grid of 3 x 3 images
for i in range(0, 9):
pyplot.subplot(330 + 1 + i)
pyplot.imshow(Image.fromarray(X_train[i]))
# show the plot
pyplot.show()

这段代码展示了如何利用Keras库加载CIFAR-10数据集,并通过matplotlib和PIL库显示其中的9张样本图像,创建了一个3x3的图像网格。
2031

被折叠的 条评论
为什么被折叠?



