2023-01-22 17:15:16 +01:00
|
|
|
# # %% [markdown]
|
|
|
|
# # # Prediction on the test data
|
|
|
|
|
|
|
|
# # %%
|
|
|
|
import os
|
|
|
|
|
|
|
|
import pandas as pd
|
|
|
|
import numpy as np
|
|
|
|
import tensorflow as tf
|
|
|
|
|
|
|
|
|
2023-01-24 18:49:32 +01:00
|
|
|
model = tf.keras.models.load_model('model_pred/VGG16_sign_char_detection_model')
|
2023-01-22 17:15:16 +01:00
|
|
|
|
|
|
|
# Get the list of all files and directories
|
2023-01-24 18:49:32 +01:00
|
|
|
path = "test_data_own"
|
2023-01-22 17:15:16 +01:00
|
|
|
dir_list = os.listdir(path)
|
|
|
|
|
|
|
|
print(dir_list)
|
|
|
|
|
|
|
|
# %%
|
|
|
|
from sklearn.preprocessing import OneHotEncoder, LabelEncoder
|
|
|
|
tf.keras.utils.load_img
|
|
|
|
|
|
|
|
class_names = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'del', 'nothing', 'space']
|
|
|
|
|
2023-01-24 18:49:32 +01:00
|
|
|
img_height=224
|
|
|
|
img_width=224
|
2023-01-22 17:15:16 +01:00
|
|
|
actual=[]
|
|
|
|
pred=[]
|
2023-01-24 18:49:32 +01:00
|
|
|
|
|
|
|
|
|
|
|
img_size = [img_height, img_width]
|
2023-01-22 17:15:16 +01:00
|
|
|
for i in dir_list:
|
|
|
|
for j in os.listdir(path+'/'+i):
|
|
|
|
file_path = path+'/'+i + '/' + j
|
|
|
|
actual.append(i)
|
2023-01-24 18:49:32 +01:00
|
|
|
test_image = tf.keras.utils.load_img(file_path, target_size = img_size)
|
2023-01-22 17:15:16 +01:00
|
|
|
test_image = tf.keras.utils.img_to_array(test_image)
|
|
|
|
test_image = np.expand_dims(test_image, axis = 0)
|
|
|
|
result = model.predict(test_image)
|
|
|
|
pred.append(class_names[np.argmax(result)])
|
|
|
|
|
|
|
|
from sklearn.metrics import confusion_matrix, classification_report
|
|
|
|
from sklearn.metrics import accuracy_score
|
|
|
|
|
|
|
|
print("Test accuracy=",accuracy_score(pred,actual))
|
|
|
|
print("Classification report:\n",classification_report(pred,actual))
|
|
|
|
|
|
|
|
|
|
|
|
# %%
|
|
|
|
|
|
|
|
|
|
|
|
|