Is there a way to preserve an order of shuffled ImageDataGenerator flow_from_directory of tensorflow?

Viewed 118

i am currently in progress of testing my dataset with tensorflow, however when i want to create a shuffled data for testing, there is a problem. when i want to create confusion matrix i need to pass (y_true, y_pred)

In my case y_true is my test_set :

test_set = test_datagen.flow_from_directory('path',
                                        target_size = (280, 280),
                                        batch_size = 32,
                                        class_mode = 'categorical',
                                        subset="validation",
                                        shuffle=True
                                        )

and i will feed test_set to model.predict() and will result in y_pred.

In this case when i want to create an array contanining labels of the shuffled data. However if i use test_set.labels it will return the labels of the ordered data which are not on shuffled state order. is there a way to output the labels of the shuffled data labels?

1 Answers

Shuffle can be controlled by setting shuffle=False.

shuffle: Whether to shuffle the data (default: True) If set to False, sorts the data in alphanumeric order.

Check here for more details.

Related