captcha_image / example.py
verytuffcat's picture
Upload 4 files (#1)
a45c8cb verified
raw
history blame contribute delete
725 Bytes
# ONNX for image classification model
import onnxruntime as ort
import numpy
from PIL import Image
ort_sess = ort.InferenceSession('model.onnx')
classes = [ "train" , "seaplane" , "motorbus" , "airplane" , "stair" , "bicycle" , "bus" , "car" , "crosswalk" , "hydrant" , "motorcycle" , "mountain" , "stairs" , "tow truck" , "traffic light" , "traffic sign" , "truck" , ]
img = Image.open("image.jpg").convert('RGB')
img = img.resize((300, 300 * img.size[1] // img.size[0]), Image.ANTIALIAS)
inp_numpy = numpy.array(img)[None].astype('float32')
class_scores = ort_sess.run(None, {'input': inp_numpy})[0][0]
print("")
print("class_scores", class_scores)
print("Class : ", classes[class_scores.argmax()])