How to get prediction from test directory?

I have trained a model with a dataflow generator on train and Val set. Now I want to get predictions on the test set. The test set is also in a directory. How could I efficiently get the prediction? I have implemented this loop as shown below but I think it is not very efficient.

If the files in the test directory are organized just like the train directory, you can use
model.evaluate(validation_generator) with your test_generator instead.

If you have a custom test directory, why don’t you organize the files like in train directory where you have the class at the top level and the images inside?