Mode:
Duration:
1
Coding works best on desktop or with an external keyboard.
Coding works best on desktop or with an external keyboard.
Performing image classification using a pretrained ONNX model.
import onnxruntime as ort
import numpy as np
from PIL import Image
# Load image
image = Image.open('image.jpg').resize((224,224))
input_data = np.array(image).astype(np.float32)
input_data = np.expand_dims(input_data, axis=0)
# Load model
session = ort.InferenceSession('resnet50.onnx')
input_name = session.get_inputs()[0].name
# Run inference
outputs = session.run(None, {input_name: input_data})
print('Predicted class:', np.argmax(outputs[0]))ONNX (Open Neural Network Exchange) is an open-source format and ecosystem for representing machine learning models, enabling interoperability between frameworks like PyTorch, TensorFlow, and scikit-learn, and allowing deployment across diverse platforms.
Origin & Creator
ONNX was co-developed by Microsoft and Facebook in 2017 to unify model representation and interoperability between deep learning frameworks.
Industrial Note
ONNX is widely used in production pipelines where models need to be transferred between frameworks, optimized for inference, or deployed on resource-constrained devices like mobile phones or edge servers.