Skip to content

Instantly share code, notes, and snippets.

@shashankprasanna
Created October 20, 2020 08:04
Show Gist options
  • Save shashankprasanna/4735affebd0f78421e86cf4433f6dff8 to your computer and use it in GitHub Desktop.
Save shashankprasanna/4735affebd0f78421e86cf4433f6dff8 to your computer and use it in GitHub Desktop.
def image_preprocess(img, reps=1):
img = np.asarray(img.resize((224, 224)))
img = np.stack([img]*reps)
img = tf.keras.applications.resnet50.preprocess_input(img)
return img
from PIL import Image
import numpy as np
import json
img= Image.open('kitten.jpg')
img = image_preprocess(img, 5)
response = predictor_gpu.predict(data=img)
probs = np.array(response['predictions'][0])
tf.keras.applications.resnet.decode_predictions(np.expand_dims(probs, axis=0), top=5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment