keras preprocess input

Solutions on MaxInterview for keras preprocess input by the best coders in the world

showing results for - "keras preprocess input"
Paulina
03 Oct 2016
1from tensorflow.keras.applications.resnet50 import ResNet50
2from tensorflow.keras.preprocessing import image
3from tensorflow.keras.applications.resnet50 import preprocess_input, decode_predictions
4import numpy as np
5
6model = ResNet50(weights='imagenet')
7
8img_path = 'elephant.jpg'
9img = image.load_img(img_path, target_size=(224, 224))
10x = image.img_to_array(img)
11x = np.expand_dims(x, axis=0)
12x = preprocess_input(x)
13
14preds = model.predict(x)
15# decode the results into a list of tuples (class, description, probability)
16# (one such list for each sample in the batch)
17print('Predicted:', decode_predictions(preds, top=3)[0])
18# Predicted: [(u'n02504013', u'Indian_elephant', 0.82658225), (u'n01871265', u'tusker', 0.1122357), (u'n02504458', u'African_elephant', 0.061040461)]
19