Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.