Images preprosessing

Screenshot 2022-09-09 005226
I have used the above code to print the images but each time I run the loop I get different images. I don’t understand why is it behaving like this. I haven’t used any random function in the code. the values are called from the train set created by the Keras preprosseing. Is it the keras function which creates a dataset which changes randomly after every time i run the code???

You have to understand what train_dataset actually is. If it’s a TF dataset, which is an “iterator” that is stateful. So in subsequent calls you are “marching through” the data.

Here’s the documentation for image_dataset_from_directory, which was used to create the datasets in question.

That inherits from tf.data.Dataset.

That means the data set has an iterator so whenever it is called it will run across the data randomly.??

No, I don’t think it’s random: it’s stepping through the dataset sequentially at the “batchsize” that was specified when you created the dataset. That’s what they mean by “iterate”.

Notice that you modified the given code a bit. They use the “take(1)” method, but you don’t. That may have some effect on what you get. Have a look at the docs and see what it says about that.