Search code examples
pythontensorflowgenerative-adversarial-networkdata-pipelinetf.data.dataset

Load custom Data into a tensorflow pipeline


I am trying to implement this code which loads the data from the
official tensorflow dataset to get it to load my data placed on my google drive

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

How can I get it to load my images into classes from classes A and B to my train_horses and train_zebras class

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']

It gives me error that it is not scriptable what can I so that the data loads in the format shown in the top code snippet


Solution

  • I would suggest you to use tf.data for pre-processing your dataset as it is proven to be more efficient than ImageDataGenerator as well as image_dataset_from_directory. this blog describes the directory structure that you should use and also it has the code to implement from tf.data for custom dataset from scratch.