Home > database >  Reason for getting different array each time when 2nd code block is executed
Reason for getting different array each time when 2nd code block is executed

Time:10-08

dataset=tf.keras.preprocessing.image_dataset_from_directory(
  "PlantVillage",
  shuffle=True,
  image_size=(IMAGE_SIZE,IMAGE_SIZE),
  batch_size=BATCH_SIZE
)

for image_batch,label_batch in dataset.take(1):
    print(image_batch[1])

When i am executing 2nd code block each time system is printing different array. could someone let me know the reason for this. I'm thinking this is because due to shuffle=True statement in first block. please correct me if i'm wrong

CodePudding user response:

Setting shuffle=True will randomize the data order. Looking at the documentation, you could set shuffle=False to sort the data alphanumerically, or use a seed to ensure your shuffles stay constant, i.e.

dataset=tf.keras.preprocessing.image_dataset_from_directory(
  "PlantVillage",
  shuffle=True,
  seed=40,
  image_size=(IMAGE_SIZE,IMAGE_SIZE),
  batch_size=BATCH_SIZE
)
  • Related