Heads up! In the next video we will be using TensorFlow! Because TensorFlow has to catch up to the latest version of Python every year, you may have to make sure you have the right version installed in order to have it work with Python. Have a read here for system requirements in case you are using a very modern version of Python that just came out that TensorFlow does not support yet https://www.tensorflow.org/install/pip (or just watch the next video).


The below script is what I will show you in the next video (but the code below has a few modifications in case you have the latest version of TensorFlow and not the version I show you in the coming video). You can always copy and paste this as a reference while you code along in the next video. (Thanks to Ben our Star Mentor for the code!)

import numpy as np
import tensorflow as tf

# from tensorflow.keras.applications.resnet50 import (
#     ResNet50,
#     decode_predictions,
#     preprocess_input,
# )

from tensorflow.keras.applications.efficientnet_v2 import (
    EfficientNetV2L,
    decode_predictions,
)

image = tf.keras.preprocessing.image.load_img("./giraffe.jpg")
input_arr = tf.keras.preprocessing.image.img_to_array(image)

# If using ResNet50, use this line:
# input_arr = tf.image.resize(input_arr, (224, 224))

# If using EfficientNetV2L, use this line:
input_arr = tf.image.resize(input_arr, (480, 480))

input_arr = np.array([input_arr])

# model = ResNet50()
model = EfficientNetV2L()

predictions = decode_predictions(model.predict(input_arr))

for _, label, prob in predictions[0]:
    print(f"{label}: {prob}")