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

**URL:** <https://community.deeplearning.ai/t/code-for-week-4-lab-1-if-u-run-locally-and-not-on-colab/519171>\
**Category:** TF Developer Professional Certificate Resources\
**Created:** [December 15, 2023, 5:40am UTC](https://community.deeplearning.ai/t/code-for-week-4-lab-1-if-u-run-locally-and-not-on-colab/519171 "2023-12-15T05:40:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Igor\_Lessio](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/igor_lessio/32/73932_2.png) [@Igor\_Lessio](https://community.deeplearning.ai/u/Igor_Lessio)\
**Post date:** [December 15, 2023, 5:40am UTC](https://community.deeplearning.ai/t/code-for-week-4-lab-1-if-u-run-locally-and-not-on-colab/519171/1 "2023-12-15T05:40:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![balaji.ambresh](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/balaji.ambresh/32/128697_2.png) [@balaji.ambresh](https://community.deeplearning.ai/u/balaji.ambresh)\
**Post date:** [December 15, 2023, 5:45am UTC](https://community.deeplearning.ai/t/code-for-week-4-lab-1-if-u-run-locally-and-not-on-colab/519171/2 "2023-12-15T05:45:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Igor\_Lessio](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/igor_lessio/32/73932_2.png) [@Igor\_Lessio](https://community.deeplearning.ai/u/Igor_Lessio)\
**Post date:** [December 15, 2023, 6:37am UTC](https://community.deeplearning.ai/t/code-for-week-4-lab-1-if-u-run-locally-and-not-on-colab/519171/3 "2023-12-15T06:37:04Z")

</div>

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.
