You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Summary: The ONNX domains and their versions are not appropriately set after converting a RandomForestClassifier model by specifying a specific target_opset.
Expected Behavior: The ONNX domains and their versions should be accordingly set when I pass them to to_onnx function.
Actual Behavior: The ONNX domains and their versions are always evaulated as follows:
fromskl2onnximportto_onnximportnumpyasnpfromsklearn.ensembleimportRandomForestClassifierfromsklearn.model_selectionimporttrain_test_splitfromsklearn.datasetsimportload_iris# Load datasetdata=load_iris()
X, y=data.data, data.target# Split dataset into training and testing setsX_train, X_test, y_train, y_test=train_test_split(X, y, test_size=0.2, random_state=42)
# Create and train the Random Forest modelrf_model=RandomForestClassifier(n_estimators=100, random_state=42)
rf_model.fit(X_train, y_train)
# Convert the trained model to ONNX formatonx=to_onnx(
rf_model,
X[:1].astype(np.float32), # Sample input for conversiontarget_opset={"": 15, "ai.onnx.ml": 2}
)
# Display the ONNX domains and their versionsdomains=onx.opset_importfordomindomains:
print("domain: %r, version: %r"% (dom.domain, dom.version))
It is the expected behabiour. There is new version for the random forest defined in opset 2 so the converter chooses the maximum version used by the operator in the model. The model is valid for every opset between this value and the value requested by the user. Should we change this behaviour?
RandomForestClassifier is using domain ai.onnx.ml, it is a different opset than ai.onnx. You may have a opset version 14 for ai.onnx and 3 for ai.onnx.ml. The same logic applies for the main opset. If you ask for opset 15 and the converter returns opset 9, it means the same model is valid for opset 9 to 15.
Description
Summary: The ONNX domains and their versions are not appropriately set after converting a
RandomForestClassifier
model by specifying a specifictarget_opset
.Expected Behavior: The ONNX domains and their versions should be accordingly set when I pass them to
to_onnx
function.Actual Behavior: The ONNX domains and their versions are always evaulated as follows:
Steps to Reproduce
Actual output:
Expected output:
Environment
Thanks in advance for your help! I look forward to any suggestions or solutions.
The text was updated successfully, but these errors were encountered: