【问题标题】:creating image dataset for DC GAN为 DC GAN 创建图像数据集
【发布时间】:2020-12-02 19:22:00
【问题描述】:

我肯定对这个感到头疼。我一直在玩 Tensorflow 的各种图像生成器教程,它很棒,但是当我尝试将自己的图像数据集用于 DC GAN 教程时,我遇到了困难。 MNIST 效果很好,名人面孔也是如此。但是当我建立自己的文件夹结构时,我无能为力地导入要使用的图像。这是我目前所处的位置:

#IMPORT PHOTOS
import pathlib
data_dir = "/Users/..../PATTERNS"
data_dir = pathlib.Path(data_dir)



train_images = tf.keras.preprocessing.image_dataset_from_directory(
    data_dir,
    labels="inferred",
    label_mode="int",
    class_names=None,
    color_mode="rgb",
    batch_size=32,
    image_size=(100, 100),
    shuffle=True,
    seed=None,
    validation_split=None,
    subset=None,
    interpolation="bilinear",
    follow_links=False,
    )

# up until this point everything works

BUFFER_SIZE = 60000
BATCH_SIZE = 256

train_images = train_images.reshape(train_images.shape[0], 28, 28, 1).astype('float32')
train_images = (train_images - 127.5) / 127.5 # Normalize the images to [-1, 1]


# Batch and shuffle the data
train_dataset = tf.data.Dataset.from_tensor_slices(dataset).shuffle(BUFFER_SIZE).batch(BATCH_SIZE)

然后我收到错误消息: AttributeError: 'BatchDataset' 对象没有属性 'reshape'

我尝试了一些其他教程并进行了大量的谷歌搜索,但还没有答案。任何帮助将不胜感激。谢谢!

【问题讨论】:

    标签: python tensorflow image-processing dataset dcgan


    【解决方案1】:

    你能克服你的问题吗?

    问题是 image_dataset_from_directory() 方法返回的 Batch 数据集对象没有 reshape 方法

    根据 tensorflow 文档

    一个 tf.data.Dataset 对象。
    如果 label_mode 为 None,则产生 float32 形状张量 (batch_size, image_size[0], image_size[1], num_channels),编码图像(有关规则,请参见下文 num_channels)。
    否则,它会产生一个元组(图像,标签),其中 图像具有形状 (batch_size, image_size[0], image_size[1], num_channels),标签遵循下述格式。

    您可以尝试以元组而不是张量的形式访问它

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-05-14
      • 1970-01-01
      • 2020-09-10
      • 2017-01-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多