I have a code as below. However ti gives me an error
which is not fixed by any advice I’ve seen on many sites including overflow*[Moderated by Moderator]*, tensorflow.org,jupyter etc.
import numpy as np
import tensorflow as tf
from tensorflow.keras.applications import MobileNetV2
from tensorflow.keras.applications.mobilenet_v2 import preprocess_input, decode_predictions
from tensorflow.keras.preprocessing import image
# Load the pre-trained MobileNetV2 model
model = MobileNetV2(weights='imagenet', include_top=True)
# Load and preprocess an image
# Replace 'path/to/your/image.jpg' with the actual file path
img_path = 'path/to/your/image.jpg'
img = image.load_img(img_path, target_size=(224, 224)) # MobileNetV2 expects images of size 224x224
x = image.img_to_array(img)
x = np.expand_dims(x, axis=0)
x = preprocess_input(x)
# Make a prediction
predictions = model.predict(x)
# Decode and print the top-3 predicted classes
for _, pred_class, prob in decode_predictions(predictions, top=3)[0]:
print(f"Predicted: {pred_class} with probability {prob}")