Question

My question is really simple, how to find the filename associated with a prediction in Keras? That is, if I have a set of 100 test samples named and I get a numpy array which contains the estimated class probabilities, how do I map the filenames to the probabilities?

import cv2
import os
import glob 

def load_test():
    X_test = []
    y_test = []
    os.chdir(testing_path)
    file_list = glob.glob('*.png')
    for test_image in file_list:
        img = cv2.imread(test_image,1)
        X_test.append(img)
        y_test.append(1)
   return X_test,y_test

if __name__ == '__main__':
   X_test = np.array(X_test, dtype = np.uint8)
   X_test = X_test.reshape(X_test.shape[0],3,100,100)
   X_test = X_test.astype('float32')
   X_test /= 255
Was it helpful?

Solution

The order of the files that populate file_list, is the same order X_test appears in, by row.

So just match the indices to correlate filename with prediction.

X_test[0] ~ prediction[0] ~ file_list[0]

Licensed under: CC-BY-SA with attribution
Not affiliated with datascience.stackexchange
scroll top