0

I'm definitely in over my head with this one. I've been playing around with Tensorflow's assorted image genorator tutorials and its great, but I get stuck when I try to use my own image dataset for the DC GAN tutorial. MNIST works great, as does the celeb faces. But when I built my own folder structure nothing I can do imports the images to use. Here's where I'm at thus far:

#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)

then I get the error message: AttributeError: 'BatchDataset' object has no attribute 'reshape'

I've tried a handful of other tutorials and done a ton of googling, but no answers yet. Any help would be greatly appreciated. Thanks!

1 Answers1

0

Could you overcome your problem?

The problem is that image_dataset_from_directory() method returns Batch dataset object which don't have a reshape method

according to tensorflow documentations

A tf.data.Dataset object.
If label_mode is None, it yields float32 tensors of shape (batch_size, image_size[0], image_size[1], num_channels), encoding images (see below for rules regarding num_channels).
Otherwise, it yields a tuple (images, labels), where images has shape (batch_size, image_size[0], image_size[1], num_channels), and labels follows the format described below.

You may try accessing it as tuple instead of tensor

Hossam Alzomor
  • 149
  • 1
  • 10