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

AttributeError: 'numpy.uintXX' object has no attribute 'encode' #813

Closed
arnauddgbes opened this issue Jan 20, 2022 · 0 comments · Fixed by #818
Closed

AttributeError: 'numpy.uintXX' object has no attribute 'encode' #813

arnauddgbes opened this issue Jan 20, 2022 · 0 comments · Fixed by #818

Comments

@arnauddgbes
Copy link

arnauddgbes commented Jan 20, 2022

Hi Team,

Found an issue similar to #476, but for sklearn.neural_network.MLPClassifier objects.
Any model trained using an unsigned integer output type fails to be converted. See below a script to reproduce the issue:

import numpy as np
from sklearn.neural_network import MLPClassifier
from skl2onnx import convert_sklearn
from skl2onnx.common.data_types import FloatTensorType

rettype = np.uint32
nbclasses = 4
nrattribs = 3
nrpts = 10

x_train = np.random.random_sample( (nrpts,nrattribs) ).astype( np.single )
y_train = (x_train[:,0].copy() * nbclasses ).astype( rettype )

model = MLPClassifier()
model.fit( x_train, y_train )

initial_type = [('float_input', FloatTensorType([None,nrattribs]))]
onnxmodel = convert_sklearn(model, initial_types=initial_type)

The conversion fails for rettype = np.uint8, np.uint16 and np.uint32, but not for signed integer types or floating-point types.
A workaround can be to modify the model output type after training, before calling convert_sklearn:
model.classes_ = model.classes_.astype( np.int32 )

Tested with Python 3.9, scikit-learn v1.0.1, skl2onnx v1.10.3

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

Successfully merging a pull request may close this issue.

1 participant