Skip to content
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

Predictions with ONNX don't support non-numeric inputs #688

Open
kindofluke opened this issue Aug 24, 2022 · 0 comments
Open

Predictions with ONNX don't support non-numeric inputs #688

kindofluke opened this issue Aug 24, 2022 · 0 comments

Comments

@kindofluke
Copy link

The ONNX prediction function attempts to cast all input columns as np.float32 making it not compatible for string and categorical features.

Within ONNXPredictor.predict, we can see the conversion (I've added the comment):

    def predict(self, data, model, **kwargs):
        super(ONNXPredictor, self).predict(data, model, **kwargs)

        input_names = [i.name for i in model.get_inputs()]
        session_result = model.run(None, {input_names[0]: data.to_numpy(np.float32)}) # CONVERSION TO FLOAT FAILS FOR STRINGs

        if len(session_result) == 0:
            raise DrumCommonException("ONNX model should return at least 1 output.")

        if len(session_result) == 1:
            preds = session_result[0]
        else:
            preds = self._handle_multiple_outputs(model, session_result)
        return preds, None

Lots of Details

Consider the example Titanic Survivors which has mixed features and uses a ColumnTransformer to apply various SkLearn transformation in a pipeline.

As noted in the example, ONNX can support a list of dictionaries as an input instead of a DataFrame:

inputs = {c: X_test2[c].values for c in X_test2.columns}
sess = rt.InferenceSession("pipeline_titanic.onnx")
pred_onx = sess.run(None, inputs)

DRUMs conversion on inbound DataFrame would fail in this case which feels like it would be very common.

@kindofluke kindofluke changed the title ONNX doesn't support non-numeric inputs Predictions with ONNX don't support non-numeric inputs Aug 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant