Accelerate and Productionize ML Model Inferencing Using Open-Source Tools

Tutorial Overview
  1. Image classification using PyTorch:

Image Classification with PyTorch

data_transforms = transforms.Compose([        transforms.RandomResizedCrop(224),        transforms.RandomHorizontalFlip(),        transforms.ToTensor(),        transforms.Normalize([0.47637546, 0.485785  , 0.4522678 ], [0.24692202, 0.24377407, 0.2667196 ])    ])data = datasets.ImageFolder(root=image_folder, transform=data_transforms)
model = models.__dict__[model_name](pretrained=True)# Alter the final layerfinal_layer_input = model.fc.in_features# nn.Linear a linear transformation to the incoming data: y = x A^T + bmodel.fc = nn.Linear(final_layer_input, num_classes)
dummy_input = torch.randn(1, 3, 224, 224)torch.onnx.export(model, dummy_input, "sports_classification.onnx")
ort_session = InferenceSession('sports_classification.onnx')result =, {'input.1': test_sample.numpy()})

Classification task with scikit-learn

model = Pipeline([('scaler', StandardScaler()),   ('predictor', MLPClassifier(random_state=42))]), y_train)
model_onnx = convert_sklearn(model, 'classification model', [('input', FloatTensorType([None, X_test.shape[1]]))])
save_model(model_onnx, 'onnx_model.onnx')
sess = InferenceSession('onnx_model.onnx')res =, input_feed={'input': X_test})




Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
ODSC - Open Data Science

ODSC - Open Data Science


Our passion is bringing thousands of the best and brightest data scientists together under one roof for an incredible learning and networking experience.