<jupyter_start><jupyter_text>Transfer Learning - 1 Making Predictions using Pre-trained Networks<jupyter_code>from keras.applications.resnet50 import ResNet50
from keras.preprocessing import image
from keras.applications.resnet50 import preprocess_input, decode_predictions
import numpy as np
#create the model

model = ResNet50(weights='imagenet')
!pip install pillow
# Read the Image
import cv2
img_path = 'image.jpg'
img = cv2.imread(img_path)
img = cv2.resize(img,(224,224))
img = cv2.cvtColor(img,cv2.COLOR_BGR2RGB)
x = image.img_to_array(img)
x = np.expand_dims(x, axis=0)
x = preprocess_input(x)

import matplotlib.pyplot as plt
plt.title("Actual Image")
plt.imshow(img)
plt.show()
plt.title("Normalised Image")
plt.imshow(x[0])
plt.show()

preds = model.predict(x)
print('Predicted:', decode_predictions(preds, top=3)[0])<jupyter_output>Predicted: [('n02504458', 'African_elephant', 0.5998083), ('n01871265', 'tusker', 0.3177723), ('n02504013', 'Indian_elephant', 0.08234573)]
{'fraction_non_alphanumeric': 0.13516260162601626, 'fraction_numerical': 0.07520325203252033, 'mean_word_length': 7.418803418803419, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '397489', 'license': 'MIT', 'n_tokens_mistral': 420, 'n_tokens_neox': 372, 'n_words': 78, 'path': '21. Transfer Learning/Transfer-Learning-1-pretrained-network.ipynb', 'repo_name': 'sgeek28/Data-Science', 'size': '984'}