<jupyter_start><jupyter_text>Testing model on the testing set<jupyter_code>#loss and accuracy on validation set
gender_model.evaluate(test_x, test_y, verbose=1)
predictions = gender_model.predict(test_x)
from sklearn.metrics import classification_report, confusion_matrix

pred_list = []; actual_list = []

for i in predictions:
    pred_list.append(np.argmax(i))

for i in test_y: 
    actual_list.append(np.argmax(i))

confusion_matrix(actual_list, pred_list)<jupyter_output><empty_output><jupyter_text>Testing modelFeed an image to find the gender<jupyter_code>from keras.preprocessing import image
from keras.preprocessing.image import ImageDataGenerator
def loadImage(filepath):
    test_img = image.load_img(filepath, target_size=(224, 224))
    test_img = image.img_to_array(test_img)
    test_img = np.expand_dims(test_img, axis = 0)
    test_img /= 255
    return test_img
picture = "Robbie.jpg" #replace by desired image to predict gender on

prediction = gender_model.predict(loadImage(picture))
img = image.load_img(picture)#, target_size=(224, 224))
plt.imshow(img)
plt.show()

gender = "Man" if np.argmax(prediction) == 1 else "Woman"

print("gender: ", gender)<jupyter_output><empty_output><jupyter_text>Test on UTK<jupyter_code>utk_info = pd.read_csv('utkCrop.csv', usecols=['age', 'gender', 'race', 'date&time', 'filename'])
utk_info.dropna(inplace=True)
pred_gender = []         
#os.chdir(r'C:\Users\user\Downloads\') # change it to where the corresponding pics locates
count=0
for file in utk_info['filename']:
    count+=1
    if count%1000 ==0:
        print(count)
    prediction = gender_model.predict(loadImage(file))
    pred_gender = np.argmax(prediction)
utk_info['pred_gender'] = pred_gender
utk_info;<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11875, 'fraction_numerical': 0.014204545454545454, 'mean_word_length': 6.044, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '437422', 'license': 'MIT', 'n_tokens_mistral': 639, 'n_tokens_neox': 611, 'n_words': 128, 'path': 'Gender_Prediction_UTK.ipynb', 'repo_name': 'coldonline/APM_Faces_Proj', 'size': '1760'}