Streaming images from directory and associating prediction with file name in tensorflow

Viewed 256

I have a trained model and I need to run inference on a large directory of images. I know I can make a generator using ImageDataGenerator.flow_from_directory but it is not obvious how to associate predicted results with file names. Ideally given a keras model + directory of images i'd like to have an array of file names and predicted probabilities. How do I accomplish this?

1 Answers

What you need to do is to separate the images into a different folder, corresponding to the class. The name of the folder should be the name of the class, by using the ImageDataGenerator.flow_from_directory() Keras will automatically infer the class names based on the directories. As an example, you should have a folder named "data" that contains 2 folders named "cat" and "dog".

Then you can call the method ImageDataGenerator.flow_from_directory("path/to/folder/data") and Keras will produce a dataset with the two classes, "cat" and "dog".

Depending on the name of the files, the separation might be easy for you with a simple program, If not, I recommend using a program that groups together similar images, and based on that you can manually create the folders.

Related