adriangb / scikeras

Scikit-Learn API wrapper for Keras.
https://www.adriangb.com/scikeras/
MIT License
239 stars 47 forks source link

How to use the wrappers function in onnx? #296

Closed praneeth5222 closed 1 year ago

praneeth5222 commented 1 year ago

Hello @adriangb

Can you guide me in using KerasClassifier in ONNX runtime?

adriangb commented 1 year ago

That's a bit general of a question. Models ran via ONNX are no longer TensorFlow models I think, so SciKeras would not be compatible with them (that is, SciKeras can't wrap an ONNX model)

praneeth5222 commented 1 year ago

Thank you @adriangb for your quick response. Tensorflow models can be converted to ONNX using tf2onnx module but I'm unable to find a module to convert a scikeras class to ONNX

adriangb commented 1 year ago

SciKeras is just a shimmy between scikit learn models and tensorflow models. I'd recommend you convert the actual tensorflow model to ONNX. SciKeras is not in and of itself a machine learning framework.

praneeth5222 commented 1 year ago

Got it!! Thank you.

praneeth5222 commented 1 year ago

I know I have closed this thread @adriangb; I just wanted your suggestion if you have any for the problem I'm facing with

So i have a Keras model that I wanted to use along with sklearn CalibratedClassifierCV to calibrate the probability outputs and convert the entire pipeline to ONNX.

Since keras model doesn't have predict_proba method inbuilt which is a requirement for CalibratedClassifierCV; I have tried to use KerasClassifier to wrap the keras model so that I can use it for calibration but then if I do so I'm not able to convert the pipeline to ONNX because of the KerasClassifier

Any thoughts or suggestions here?

adriangb commented 1 year ago

convert the entire pipeline to ONNX.

That’s going to be the issue: as far as I know ONNX introspects the Pipeline and special cases sklearn transformers and models that it recognizes. It won’t recognize the wrapped tensorflow model unfortunately. Could you export just the TensorFlow model and re-create your sklearn pipeline when you want to do inference and use it as a transformer?

praneeth5222 commented 1 year ago

Could you export just the TensorFlow model and re-create your sklearn pipeline when you want to do inference and use it as a transformer?

Do you mind explaining this, when you say recreating your sklearn pipeline? Here I do want to recalibrate the prediction probabilities from the Tensorflow Keras model every time the model train happens and use them both in the runtime using ONNX

praneeth5222 commented 3 months ago

Hi @adriangb I have stumbled on this issue once again. Can you explain the above-said statement?