【问题标题】:Load custom Data into a tensorflow pipeline将自定义数据加载到张量流管道中
【发布时间】:2021-11-27 12:27:19
【问题描述】:

我正在尝试实现从
加载数据的代码 官方 tensorflow 数据集,让它加载我放置在我的谷歌驱动器上的数据

dataset, metadata = tfds.load('cycle_gan/horse2zebra',
                              with_info=True, as_supervised=True)
train_horses, train_zebras = dataset['trainA'], dataset['trainB']

如何让它将我的图像加载到从 A 类和 B 类到我的 train_horses 和 train_zebras 类的类中

train_dataset=tf.keras.utils.image_dataset_from_directory(
    '/content/drive/MyDrive/ColorGan', labels='inferred', label_mode='int',
    class_names=None, color_mode='rgb', batch_size=32, image_size=(256,
    256), shuffle=True, seed=2000, validation_split=0.2, subset='training',
    interpolation='bilinear', follow_links=False,
    crop_to_aspect_ratio=False)
test_dataset=tf.keras.utils.image_dataset_from_directory(
    '/content/drive/MyDrive/ColorGan', labels='inferred', label_mode='int',
    class_names=None, color_mode='rgb', batch_size=32, image_size=(256,
    256), shuffle=True, seed=2000, validation_split=0.2, subset='validation',
    interpolation='bilinear', follow_links=False,
    crop_to_aspect_ratio=False)

train_horses, train_zebras = train_dataset['A'],train_dataset['B']

它给了我一个错误,它不是可编写脚本的,我该怎么做才能以顶部代码 sn-p 中显示的格式加载数据

【问题讨论】:

    标签: python tensorflow generative-adversarial-network data-pipeline tf.data.dataset


    【解决方案1】:

    我建议您使用 tf.data 来预处理您的数据集,因为事实证明它比 ImageDataGenerator 更有效 以及 image_dataset_from_directorythis blog 描述了您应该使用的目录结构,并且它还包含从 tf.data 实现的代码,用于从头开始自定义数据集。

    【讨论】:

      【解决方案2】:

      用于创建 Tensorflow 数据管道的示例工作代码

      import pathlib
      data_dir = pathlib.Path('/content/images/horses')
      import tensorflow as tf
      batch_size = 16
      img_height = 180
      img_width = 180
      train_horses = tf.keras.preprocessing.image_dataset_from_directory(
        data_dir,
        validation_split=0.2,
        subset="training",
        seed=123,
        image_size=(img_height, img_width),
        batch_size=batch_size)
      
      import pathlib
      data_dir = pathlib.Path('/content/images/zebras')
      
      import tensorflow as tf
      batch_size = 16
      img_height = 180
      img_width = 180
      train_zebras = tf.keras.preprocessing.image_dataset_from_directory(
        data_dir,
        validation_split=0.2,
        subset="training",
        seed=123,
        image_size=(img_height, img_width),
        batch_size=batch_size)
      
      ds = train_horses.concatenate(train_zebras)
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-12-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-08-23
        • 1970-01-01
        • 2017-05-25
        相关资源
        最近更新 更多