Keras introduced tf.keras.preprocessing.image_dataset_from_directory function recently, which is more efficient than previously ImageDataGenerator.flow_from_directory method in tensorflow 2.x.
I am practising on the catsvsdogs problems and using this function to build a data pipeline for my model. After training the model, I use preds = model.predict(test_ds) to get the predictions for my test dataset. How should I match the preds with the name of pictures? (There is generator.filenames before, but doesn't exist in the new method any more.) Thanks!
image_dataset_from_directory allows to load your data in the tf. data. Dataset format. Hence, it enables also the use, and this is the best, of the Keras preprocessing layers, including data augmentation.
In memory data For any small CSV dataset the simplest way to train a TensorFlow model on it is to load it into memory as a pandas Dataframe or a NumPy array. A relatively simple example is the abalone dataset. The dataset is small. All the input features are all limited-range floating point values.
The easiest way to load your dataset for training or testing is by using Keras ImageDataGenerator class (that also allows you some data augmentation methods). You have 3 options : If your dataset is structured like this : data/ train/ dogs/ dog001.
Expanding on @Daniel Woolcott's and @Almog David's answers, the file paths are returned by the image_dataset_from_directory()
function in Tensorflow v2.4. already. No need to change the source code of the function.
To be more exact – you can easily retrieve the paths with the file_paths
attribute.
Try this:
img_folder = "your_image_folder/"
img_generator = keras.preprocessing.image_dataset_from_directory(
img_folder,
batch_size=32,
image_size=(224,224)
)
file_paths = img_generator.file_paths
print(file_paths)
Prints out:
your_file_001.jpg
your_file_002.jpg
…
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With