Skip to content

Instantly share code, notes, and snippets.

@rpitonak
Last active July 12, 2022 08:04
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 rpitonak/19299c3681fccc1da1fd07d5b0a8fa34 to your computer and use it in GitHub Desktop.
Save rpitonak/19299c3681fccc1da1fd07d5b0a8fa34 to your computer and use it in GitHub Desktop.
# !wget https://github.com/EliSchwartz/imagenet-sample-images/raw/master/n02085936_Maltese_dog.JPEG
large_img = np.array(Image.open("n02085936_Maltese_dog.JPEG"))
print(f"Image shape: {large_img.shape}")
plt.imshow(large_img)
# Output:
# Image shape: (500, 375, 3)
sess = rt.InferenceSession("combined_dynamic_input.onnx") # Start the inference session and open the model
input_image = np.expand_dims(large_img.astype(np.float32), 0) # Use the input_example from block 0 as input
output = sess.run(["softmaxout_1"], {"X": input_image}) # Compute the standardized output
print("Check:")
print(np.shape(output))
print("Index ", np.argmax(output))
print("Confidence ", np.max(output))
# Output:
# Check:
# (1, 1, 1000, 1, 1)
# Index 153
# Confidence 0.9580029
# According to imagenet index to text list https://gist.github.com/yrevar/942d3a0ac09ec9e5eb3a we can see that 153 stands for 'Maltese dog, Maltese terrier, Maltese'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment