Code for Week 4 Lab 1 if u run locally and not on colab

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()

Sorry I don’t follow. Could you please explain the rationale behind the post?

Maybe my code was not formatted properly.
I run locally and the code that call collab to get a picture from the local machine not work if u are into and ENV.

So i posted a code for who like me run locally on GPU.
I hope this is not an issue.