Hi everyone !
I run all locally so i had to workout a function to check the images locally.
import numpy as np
from tkinter import filedialog
from tkinter import Tk
from keras.preprocessing import image
import os
def load_and_predict():
# Initialize Tkinter root
root = Tk()
root.withdraw() # we don't want a full GUI
# Show an "Open" dialog box and return the path(s) to selected file(s)
file_paths = filedialog.askopenfilenames() # allows multiple file selection
# Process each selected file
for file_path in file_paths:
# Load and preprocess the image
img = image.load_img(file_path, target_size=(300, 300))
x = image.img_to_array(img)
x = np.expand_dims(x, axis=0)
images = np.vstack([x])
# Predict the class
classes = model.predict(images, batch_size=10)
print(classes[0])
# Determine and print the prediction
if classes[0] > 0.5:
print(os.path.basename(file_path) + " is a human")
else:
print(os.path.basename(file_path) + " is a horse")
load_and_predict()