-
-
Save tkeyo/6777893acbed14386c455d441714ba84 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import onnxruntime as rt | |
labels = ['hot_dog', 'not_hot_dog'] | |
# get image as tensor - 1 x 3 x 256 x 256 dimensions | |
hot_dog_tensor_onnx = image_transform_onnx('test_images/hot_dog_114.jpg', 256) | |
# initialize onnx runtime inference session | |
sess = rt.InferenceSession('models/hot_dog_model_resnet18_256_256.onnx') | |
# input & output names | |
input_name = sess.get_inputs()[0].name | |
output_name = sess.get_outputs()[0].name | |
# input dimensions (important for debugging) | |
input_dims = sess.get_inputs()[0].shape | |
print(input_name, output_name, input_dims) | |
results = sess.run([output_name], {input_name: not_hot_dog_tensor_onnx})[0] | |
print(labels[np.argmax(results)], results) | |
# prints | |
# ('hot_dog',array([[0.9986059 , 0.00139411]], dtype=float32)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment