python.data.ops.dataset_ops.BatchDataset - how to use it to create training and test datasets

Viewed 5683

Using TensorFlow to walk directories and take images which i want to use in training a NN.

train_ds = tf.keras.preprocessing.image_dataset_from_directory(
    wk_dir,
    labels="inferred",
    label_mode="int",
    class_names=None,
    color_mode="grayscale",
    batch_size=batches,
    image_size=image_dim,
    shuffle=True,
    seed=1968,
    validation_split=0.2,
    subset="training",
    interpolation="bilinear",
    follow_links=False,
)

Found 127561 files belonging to 3 classes. Using 102049 files for training.

Result - it works....now i am trying to use this to input into a model and not sure how to manage it...

print(train_ds)
<BatchDataset shapes: ((None, 576, 432, None), (None,)), types: (tf.float32, tf.int32)>

So do i have 2 elements in the array one with 4 elements, 2 of which are empty and a 2nd element whic his the classification?
i have tried to split the BatchDatashape and get error TypeError: 'BatchDataset' object is not subscriptable

how do you manipulate a TF of object type python.data.ops.dataset_ops.BatchDataset ?

2 Answers

You have one dataset name -train_ds. If you want validation dataset you will need to write one more statement, difference is in the subset name:

train_ds = tf.keras.preprocessing.image_dataset_from_directory(
    wk_dir,
    labels="inferred",
    label_mode="int",
    class_names=None,
    color_mode="grayscale",
    batch_size=batches,
    image_size=image_dim,
    shuffle=True,
    seed=1968,
    validation_split=0.2,
    subset="validation",
    interpolation="bilinear",
    follow_links=False,
)
Related