如何使用TensorFlow显示来自猫狗输入数据集的样本数据?


TensorFlow可以使用‘matplotlib’库来显示来自猫狗输入数据集的样本数据。“imshow”方法可以用来在控制台上显示图像。

阅读更多: 什么是TensorFlow以及Keras如何与TensorFlow一起创建神经网络?

我们将了解如何利用预训练网络的迁移学习来对猫和狗的图像进行分类。

图像分类迁移学习背后的直觉是,如果一个模型在一个大型且通用的数据集上进行训练,那么这个模型可以有效地作为一个通用的视觉世界模型。它已经学习了特征图,这意味着用户不必从头开始在大型数据集上训练大型模型。

阅读更多: 如何预训练自定义模型?

我们使用Google Colaboratory来运行以下代码。Google Colab或Colaboratory帮助在浏览器上运行Python代码,无需任何配置,并且可以免费访问GPU(图形处理单元)。Colaboratory是基于Jupyter Notebook构建的。

示例

class_names = train_dataset.class_names
print("Sample dataset being displayed on console")
plt.figure(figsize=(10, 10))
for images, labels in train_dataset.take(1):
   for i in range(9):
      ax = plt.subplot(3, 3, i + 1)
      plt.imshow(images[i].numpy().astype("uint8"))
      plt.title(class_names[labels[i]])
      plt.axis("off")

代码来源 −https://tensorflowcn.cn/tutorials/images/transfer_learning

输出

解释

  • 对图像进行迭代,并在控制台上显示图像样本。

更新于:2021年2月25日

78 次浏览

启动您的职业生涯

完成课程后获得认证

开始
广告
© . All rights reserved.