我肯定对这个感到头疼。我一直在玩 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' object has no attribute 'reshape'
我已经尝试了一些其他教程并进行了大量的谷歌搜索,但还没有答案。任何帮助将不胜感激。谢谢!