In [40]: import numpy as np
import tensorflow as tf
In [41]: from [Link].vgg16 import VGG16, preprocess_input, decode_predictions
from [Link] import image
from [Link].resnet50 import ResNet50, preprocess_input, decode_predictions
In [44]: model = VGG16(weights='imagenet')
img_path = "img [Link]"
img = image.load_img(img_path, target_size=(224, 224))
In [45]: img_array = image.img_to_array(img)
img_array = np.expand_dims(img_array, axis=0)
img_array = preprocess_input(img_array)
predictions = [Link](img_array)
1/1 ━━━━━━━━━━━━━━━━━━━━ 0s 367ms/step
In [46]: model = ResNet50(weights='imagenet')
img_path = "img [Link]"
img = image.load_img(img_path, target_size=(224, 224))
img_array = image.img_to_array(img)
img_array = np.expand_dims(img_array, axis=0)
img_array = preprocess_input(img_array)
predictions = [Link](img_array)
decoded_predictions = decode_predictions(predictions, top=3)[0]
for i, (imagenet_id, label, score) in enumerate(decoded_predictions):
print(f"{i+1}: {label} ({score:.2f})")
1/1 ━━━━━━━━━━━━━━━━━━━━ 1s 1s/step
1: zebra (0.98)
2: hartebeest (0.00)
3: cheetah (0.00)
In [47]: from [Link] import display
from PIL import Image
img_path = "img [Link]"
img = [Link](img_path)
display(img)
In [ ]: