-
Notifications
You must be signed in to change notification settings - Fork 110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
graph may be disconnected with StackingClassifier #1069
Comments
skl2onnx cannot translate such an expression |
replaced all
did it work for you replacing for def abc_Embedder() -> list[tuple[str, Any]]:
return [
("cast64", skl2onnx.sklapi.CastTransformer(dtype=numpy.float64)),
("scaler", preprocessing.StandardScaler()),
("cast32", skl2onnx.sklapi.CastTransformer()),
("basemodel", lightgbm.LGBMClassifier()),
]
def Classifier(features: list[str]) -> base.BaseEstimator:
facepreprocessor = compose.ColumnTransformer([("identity", "passthrough", [i for i, x in enumerate(features) if x.startswith("facelandmark")])])
posepreprocessor = compose.ColumnTransformer([("identity", "passthrough", [i for i, x in enumerate(features) if x.startswith("poselandmark")])])
faceembedder = pipeline.Pipeline(steps=abc_Embedder())
poseembedder = pipeline.Pipeline(steps=abc_Embedder())
facepipeline = pipeline.Pipeline([("preprocessor", facepreprocessor), ("embedder", faceembedder)])
posepipeline = pipeline.Pipeline([("preprocessor", posepreprocessor), ("embedder", poseembedder)])
head = linear_model.LogisticRegression(multi_class="multinomial")
classifier = ensemble.StackingClassifier(
estimators=[("facepipeline", facepipeline), ("posepipeline", posepipeline)],
final_estimator=head
)
return classifier any idea why the error may persist? |
any pointers on that, @xadupre? |
After digging deeper, it seems like the problem arises only when exporting the stacking classifier with the lightGBM model as backbone, while the lightGBM model alone and the preprocessing work fine, @xadupre I have also tried replacing the ligthGBM classifiers with logistic regressions or with hist gradient boosting classifiers, and replacing the logistic regression head with other available classifiers, but the error is always the same. The weird thing is that I tried the notebook shared in #817, which also uses a stacking classifier, and the export works. |
For some reason, the nested pipeline definition was the problem, @xadupre. The following definition works as expected: def abc_Embedder() -> list[tuple[str, Any]]:
return [
("cast64", skl2onnx.sklapi.CastTransformer(dtype=numpy.float64)),
("scaler", preprocessing.StandardScaler()),
("cast32", skl2onnx.sklapi.CastTransformer()),
("basemodel", lightgbm.LGBMClassifier()),
]
def Classifier(features: list[str]) -> base.BaseEstimator:
facepreprocessor = compose.ColumnTransformer([("identity", "passthrough", [i for i, x in enumerate(features) if x.startswith("facelandmark")])])
posepreprocessor = compose.ColumnTransformer([("identity", "passthrough", [i for i, x in enumerate(features) if x.startswith("poselandmark")])])
faceembedder = abc_Embedder()
poseembedder = abc_Embedder()
facepipeline = pipeline.Pipeline([("preprocessor", facepreprocessor), *faceembedder])
posepipeline = pipeline.Pipeline([("preprocessor", posepreprocessor), *poseembedder])
head = linear_model.LogisticRegression(multi_class="multinomial")
classifier = ensemble.StackingClassifier(
estimators=[("facepipeline", facepipeline), ("posepipeline", posepipeline)],
final_estimator=head
)
return classifier |
Sorry for the delay, I was able to create a unit test from the notebook you shared. I can replicate the bug. I will work on a fix. |
PR #1072 fixes it. Sorry for the delay again. Feel free to reopen it if you have another issue with it. |
Hello,
I have a complex scikit-learn pipeline which I have been trying to convert to ONNX.
The complexity comes from me trying to "mask out" parts of the input for different components of the pipeline and using a lightGBM classifier as base model, but the pipeline is being trained and run successfully when using standard scikit-learn.
To put the pipeline together and convert it to ONNX I have drawn inspiration from the following tutorials:
The error I am getting when trying to export the pipeline is the following:
I will attach the archived Jupyter notebook for reproducibility on Google Colab: notebook.zip
am I missing something in the pipeline definition or in the export? What's wrong?
The text was updated successfully, but these errors were encountered: