I want to check if the predictions my model is computing are correct.
I have already trained my model and saved it. My dataset is created using tf.keras.preprocessing.image_dataset_from_directory as following :
ds_train = tf.keras.preprocessing.image_dataset_from_directory(
'data/',
labels = 'inferred',
label_mode = 'categorical',
color_mode = 'rgb',
batch_size = batch_size,
image_size = (img_height, img_width),
shuffle = True,
seed = 123,
validation_split = 0.1,
subset = 'training',
)
ds_validation = tf.keras.preprocessing.image_dataset_from_directory(
'data/',
labels = 'inferred',
label_mode = 'categorical',
color_mode = 'rgb',
batch_size = batch_size,
image_size = (img_height, img_width),
shuffle = True,
seed = 123,
validation_split = 0.1,
subset = 'validation',
)
As my model is working and is evaluated with an accuracy of 95.65% :
Found 921 files belonging to 2 classes.
Using 829 files for training.
Found 921 files belonging to 2 classes.
Using 92 files for validation.
Epoch 1/5
104/104 - 12s - loss: 0.1335 - accuracy: 0.9867
Epoch 2/5
104/104 - 5s - loss: 0.1017 - accuracy: 0.9879
Epoch 3/5
104/104 - 5s - loss: 0.0207 - accuracy: 0.9952
Epoch 4/5
104/104 - 5s - loss: 0.0603 - accuracy: 0.9879
Epoch 5/5
104/104 - 5s - loss: 0.0127 - accuracy: 0.9964
12/12 - 0s - loss: 0.2097 - accuracy: 0.9565
I have created a test_dataset the same way as I created my training and validation datasets.
ds_test = tf.keras.preprocessing.image_dataset_from_directory(
'test/',
labels = 'inferred',
label_mode = 'categorical',
color_mode = 'rgb',
batch_size = batch_size,
image_size = (img_height, img_width),
shuffle = True,
seed = 123,
)
I know want to predict the entire test_dataset using model.predict(). My data is stored in subfolders as followed :
---test/
---label1/
---label2/
I manage to recover all the predictions for all my images but I am not able to check if the predictions are correct. Is there any way to store the label of the image predicted in a list ? I would like to use something like this :
for i in test_dataset :
list_labels = test_dataset.class_names(i)
predictions = model.predict(test_dataset)
predictions = np.argmax(predictions, axis=1)
So I can check the predictions output and link the predictions with labels. Futhermore, I don't knwo why but I am not able to get the labels using like (x_train, y_train) = mnist.load_data :
# It is not working
(x_test, y_test) = test_dataset