【问题标题】:How to transform tensorflow PrefetchDataset to use it with ImageDataGenerator for data augmentation?如何转换 tensorflow PrefetchDataset 以将其与 ImageDataGenerator 一起用于数据扩充?
【发布时间】:2022-12-04 00:30:49
【问题描述】:

我是 tensorflow 和 keras 的新手,我对工作的“cats_vs_dogs”tensorflow 数据集有一个习惯。我正在使用 tfds.load() 函数加载它,它为我提供了一个 PrefetchDataset 类型的对象。我需要向该数据集的训练拆分添加数据扩充,我想将 tf.keras.preprocessing.image.ImageDataGenerator 与它的 flow() 函数一起使用。我试图按如下方式转换我的数据集:

trainDataset = list(trainDataset)
trainDataset = tf.data.Dataset.from_tensor_slices(trainDataset)

但我一直收到InvalidArgumentError: cannot compute Pack as input #1(zero-based) was expected to be a uint8 tensor but is a int64 tensor [Op:Pack] name: 0

没有这个转换,当调用这个函数时:

train_generator = train_datagen.flow(trainDataset, batch_size = 20)

我得到float() argument must be a string or a number, not 'PrefetchDataset'

我如何转换此数据集才能将其与 ImageDataGenerator 一起使用? 或者在这种情况下我可以使用哪个其他方法来进行数据扩充?

【问题讨论】:

    标签: python tensorflow keras


    【解决方案1】:

    我也是TensorFlow的新手,现在也面临这个问题。你解决了吗? :(

    【讨论】:

      猜你喜欢
      • 2021-01-12
      • 1970-01-01
      • 2021-04-20
      • 2018-01-30
      • 2020-06-05
      • 2020-04-17
      • 1970-01-01
      • 2021-02-10
      • 2020-07-17
      相关资源
      最近更新 更多