如何使用 Tensorflow 和 Python 来验证 CIFAR 数据集?
pythonserver side programmingprogrammingtensorflow更新于 2024/6/12 20:28:17
可以通过在控制台上绘制数据集中的图像来验证 CIFAR 数据集。由于 CIFAR 标签是数组,因此需要额外的索引。‘matplotlib’ 库中的 ‘imshow’ 方法用于显示图像。
阅读更多: 什么是 TensorFlow,以及 Keras 如何与 TensorFlow 配合使用来创建神经网络?
我们正在使用 Google Colaboratory 来运行以下代码。 Google Colab 或 Colaboratory 可帮助在浏览器上运行 Python 代码,无需配置,并可免费访问 GPU(图形处理单元)。Colaboratory 是在 Jupyter Notebook 之上构建的。
print("验证数据")
plt.figure(figsize=(10,10))
print("绘制前 15 张图像")
print("由于 CIFAR 标签是数组,因此需要额外的索引")
for i in range(15):
plt.subplot(5,5,i+1)
plt.xticks([])
plt.yticks([])
plt.grid(False)
plt.imshow(train_images[i], cmap=plt.cm.binary)
plt.xlabel(class_names[train_labels[i][0]])
plt.show()
代码来源:https://www.tensorflow.org/tutorials/images/cnn
输出
验证数据 绘制前 15 幅图像 由于 CIFAR 标签是数组,因此需要额外的索引
解释
- 标准化的数据将被可视化。
- 这是使用 'matplotlib' 库完成的。
相关文章
有用资源
python 参考教程 - 该教程包含有关 python 的更多信息:https://www.cainiaomax.com/python/

