Skip to content

Instantly share code, notes, and snippets.

@frogermcs
Created May 21, 2019 18:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frogermcs/d08046c33f2d040fd43adcd8ed303ec3 to your computer and use it in GitHub Desktop.
Save frogermcs/d08046c33f2d040fd43adcd8ed303ec3 to your computer and use it in GitHub Desktop.
imgUrl = "https://upload.wikimedia.org/wikipedia/commons/thumb/d/de/Compaqarmada7800.jpg/1024px-Compaqarmada7800.jpg"
img = Image.open(requests.get(imgUrl, stream=True).raw)
img.load()
img = img.resize((224, 224), PIL.Image.ANTIALIAS)
# Normalize to [0, 1]
data = np.asarray( img, dtype="int32" ) / 255.0
# Inference on input data normalized to [0, 1]
inputImg = np.expand_dims(data,0).astype(np.float32)
input_details = mobilenetV2F_interpreter.get_input_details()
mobilenetV2F_interpreter.set_tensor(input_details[0]['index'], inputImg)
mobilenetV2F_interpreter.invoke()
output_details = mobilenetV2F_interpreter.get_output_details()
output_data = mobilenetV2F_interpreter.get_tensor(output_details[0]['index'])
print("Predicted value for [0, 1] normalization. Label index: {}, confidence: {:2.0f}%"
.format(np.argmax(output_data), 100 * output_data[0][np.argmax(output_data)]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment