Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
INPUT_TENSOR = "input__0"
OUTPUT_TENSOR = "MobilenetV2__Predictions__Reshape_1__0"
PREDICTED_FEATURE_NAME = "classLabel"
# Prediction is run on CPU
coreml_output_golden = mlmodel.predict({INPUT_TENSOR: img_golden}, useCPUOnly=True)
#Prediction is run on GPU
coreml_output_laptop = mlmodel.predict({INPUT_TENSOR: img_laptop}, useCPUOnly=False)
predicted_label_for_golden = coreml_output_golden[PREDICTED_FEATURE_NAME]
predicted_label_for_laptop = coreml_output_laptop[PREDICTED_FEATURE_NAME]
print("Prediction for Golden Retriever:",
predicted_label_for_golden,
coreml_output_golden[OUTPUT_TENSOR][predicted_label_for_golden])
print("Prediction for laptop:",
predicted_label_for_laptop,
coreml_output_laptop[OUTPUT_TENSOR][predicted_label_for_laptop])
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.