I am working with Azure AutoML and have created a trial using different models. In the pipeline, the final step is a PipelineWithYTransformations.
Now, I am attempting to convert the generated .pkl model to an ONNX model, but I encounter the following error:
raise RuntimeError("Unable to find a shape calculator for type "
RuntimeError: Unable to find a shape calculator for type '<class 'azureml.training.tabular.models.pipeline_with_ytransformations.PipelineWithYTransformations'>'.
I am unsure how to handle this error and successfully convert the model to ONNX format.
Here are some additional details about my setup:
- The AutoML trial was created with the goal of training a machine learning model.
from azure.ai.ml import automl, Input
from azure.ai.ml.constants import AssetTypes
dataset_name = "DataSetName"
my_training_data_input = Input(type=AssetTypes.MLTABLE, path=dataset_name)
# configure the classification job
classification_job = automl.classification(
compute="my_compute",
experiment_name="my_experiment",
training_data=my_training_data_input,
target_column_name="Label",
primary_metric="accuracy",
n_cross_validations=5,
enable_model_explainability=True,
tags={"my_custom_tag": "My custom value"}
)
# Limits are all optional
classification_job.set_limits(
timeout_minutes=600,
trial_timeout_minutes=20,
max_trials=2,
enable_early_termination=True,
)
# Training properties are optional
classification_job.set_training(
blocked_training_algorithms=["logistic_regression"],
enable_onnx_compatible_models=True
)
# Submit automl job
returned_job = ml_client.jobs.create_or_update(
classification_job
)
- I have tried using the convert function from the skl2onnx library to perform the conversion.
- The error seems to be related to the specific type of model (PipelineWithYTransformations) generated by AutoML. I would appreciate any guidance or suggestions on how to resolve this issue and successfully convert the model to ONNX format.
Thank you!
One possible solution to get
ONNX format model
withAzure Auto ML
from yourrun object
.Is by using
get_output:
Also, you can use
OnnxConverter Class
for saving the model in onnx format.For detailed steps and sample code please check this sample notebook.
For SDKv2 (Update) : On executing the provided script, the
onnx format
model will be generated alongside pickle model. To get the model you can use the below code snippet:This will download all the artifacts including
model.onnx file
.For more details, you can check this sample notebook.