【问题标题】:How do I load image datasets into TensorFlow?如何将图像数据集加载到 TensorFlow 中?
【发布时间】:2020-03-27 00:38:36
【问题描述】:

我是 TensorFlow 新手,我正在尝试在 Google Colaboratory 中构建一个小型神经网络。该网络的目标是根据图像识别个人的职业。我有 10 个不同工作的 900 张不同的图像作为我的训练数据,每个工作有 200 张不同的图像作为我的测试数据。测试和训练数据都下载到我的电脑上。任何帮助将不胜感激。

【问题讨论】:

标签: python python-3.x image tensorflow tensorflow2.0


【解决方案1】:

首先将您的 Google Drive 安装到 Collaboratory

from google.colab import drive
drive.mount('/content/drive')

训练和测试数据所在目录的路径

train_dir  = '/content/drive/Training'
test_dir = '/content/drive/Testing'

为训练和测试创建数据生成器

train_datagen = ImageDataGenerator(**datagen_kwargs)
test_datagen = ImageDataGenerator(**datagen_kwargs)

train_data = train_datagen.flow_from_directory(
    train_dir,
    target_size = (img_width, img_height),
    shuffle=True,
    batch_size = batch_size,
    classes = list(class_names))

test_data = test_datagen.flow_from_directory(
    test_dir,
    target_size = (img_width, img_height),
    shuffle=True,
    batch_size = batch_size,
    classes = list(class_names))

更多信息请参考link

【讨论】:

  • @noahmessijr,如果它回答了您的问题,请您接受并投票。谢谢
猜你喜欢
  • 2019-10-01
  • 1970-01-01
  • 2021-11-30
  • 2022-12-23
  • 1970-01-01
  • 2020-11-06
  • 1970-01-01
  • 2020-12-08
  • 2020-09-09
相关资源
最近更新 更多