我正在学习Udacity的Intro to TensorFlow for Deep Learning门课程.其中一节课是通过一个Google Colab笔记本来学习如何使用Fashion MNIST数据集(Colab和GitHub个链接).
显示数据集中的图像时,代码总是使用NumPy方法take()
提取第一个图像.我想知道如何访问数据集的不同部分,但我对Python的知识还不够.
第一个例子是:
# Take a single image, and remove the color dimension by reshaping
for image, label in test_dataset.take(1):
break;
image = image.numpy().reshape((28,28))
我该怎么做才能只拿第二个?
通过阅读this question的一些答案,我发现了skip()
方法,但它似乎需要所有元素,直到结束,但我只想提取几个项目,在本例中仅提取一个.
第二个例子是:
plt.figure(figsize=(10,10))
for i, (image, label) in enumerate(train_dataset.take(25)):
image = image.numpy().reshape((28,28))
plt.subplot(5,5,i+1)
plt.xticks([])
plt.yticks([])
plt.grid(False)
plt.imshow(image, cmap=plt.cm.binary)
plt.xlabel(class_names[label])
plt.show()
这一条包含了前25条:我如何开始阅读第100条的图像?
在第三个也是最后一个例子中,他们做了一件非常相似的事情:
for test_images, test_labels in test_dataset.take(1):
test_images = test_images.numpy()
test_labels = test_labels.numpy()
predictions = model.predict(test_images)
如何从第二批或第三批数据开始?