question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Hello! Following pipeline doesn’t convert for me:

classifier = LogisticRegression(C=0.01, 
                                random_state=SEED,
                                class_weight=dict(zip([False, True], c_w)),
                                n_jobs=40,
                                max_iter=500
                                solver='lbfgs',
                                verbose = 10,
                                tol=1e-3)

numeric_transformer = Pipeline(steps=[
    ('imputer', SimpleImputer(strategy='median')),
    ('scaler', StandardScaler())
])

categorical_transformer = Pipeline(steps=[
    ('imputer', SimpleImputer(strategy='constant', fill_value='nan')),
    ('onehot', OneHotEncoder(sparse=True, handle_unknown='ignore')),
    ('tsvd', TruncatedSVD(n_components=60,
                          algorithm='arpack',
                          random_state=SEED,
                          tol=1e-4))
])

preprocessor = ColumnTransformer(
    transformers=[
        ('num', numeric_transformer, numeric_features),
        ('cat', categorical_transformer, categorical_features)
    ])

model = Pipeline(steps=[
    ('precprocessor', preprocessor),
    ('classifier', classifier)
])

model.fit(X_train, y_train)

initial_type = [('s1', StringTensorType([1,15])), ('float1', FloatTensorType([1,21])),
                ('s2', StringTensorType([1,27])), ('float2', FloatTensorType([1,30]))]

onnx = convert_sklearn(model, initial_types=initial_type)

This strange error occurs:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-134-d0cc22f876ed> in <module>
----> 1 onnx = convert_sklearn(model, initial_types=initial_type)

/opt/conda/lib/python3.6/site-packages/skl2onnx/convert.py in convert_sklearn(model, name, initial_types, doc_string, target_opset, custom_conversion_functions, custom_shape_calculators)
     62     target_opset = target_opset if target_opset else get_opset_number_from_onnx()
     63     # Parse scikit-learn model as our internal data structure (i.e., Topology)
---> 64     topology = parse_sklearn(model, initial_types, target_opset, custom_conversion_functions, custom_shape_calculators)
     65 
     66     # Infer variable shapes

/opt/conda/lib/python3.6/site-packages/skl2onnx/_parse.py in parse_sklearn(model, initial_types, target_opset, custom_conversion_functions, custom_shape_calculators)
    294 
    295     # Parse the input scikit-learn model as a Topology object.
--> 296     outputs = _parse_sklearn(scope, model, inputs)
    297 
    298     # THe object raw_model_container is a part of the topology we're going to return. We use it to store the outputs of

/opt/conda/lib/python3.6/site-packages/skl2onnx/_parse.py in _parse_sklearn(scope, model, inputs)
    235     '''
    236     if isinstance(model, pipeline.Pipeline):
--> 237         return _parse_sklearn_pipeline(scope, model, inputs)
    238     elif isinstance(model, pipeline.FeatureUnion):
    239         return _parse_sklearn_feature_union(scope, model, inputs)

/opt/conda/lib/python3.6/site-packages/skl2onnx/_parse.py in _parse_sklearn_pipeline(scope, model, inputs)
    160     '''
    161     for step in model.steps:
--> 162         inputs = _parse_sklearn(scope, step[1], inputs)
    163     return inputs
    164 

/opt/conda/lib/python3.6/site-packages/skl2onnx/_parse.py in _parse_sklearn(scope, model, inputs)
    239         return _parse_sklearn_feature_union(scope, model, inputs)
    240     elif isinstance(model, ColumnTransformer):
--> 241         return _parse_sklearn_column_transformer(scope, model, inputs)
    242     elif type(model) in sklearn_classifier_list and type(model) not in [LinearSVC, SVC, NuSVC]:
    243         probability_tensor = _parse_sklearn_simple_model(scope, model, inputs)

/opt/conda/lib/python3.6/site-packages/skl2onnx/_parse.py in _parse_sklearn_column_transformer(scope, model, inputs)
    213         transform_inputs = _fetch_input_slice(scope, inputs, column_indices)
    214         transformed_result_names.append(_parse_sklearn_simple_model(scope, model.named_transformers_[name],
--> 215                                                                     transform_inputs)[0])
    216     # Create a Concat ONNX node
    217     concat_operator = scope.declare_local_operator('SklearnConcat')

/opt/conda/lib/python3.6/site-packages/skl2onnx/_parse.py in _parse_sklearn_simple_model(scope, model, inputs)
    131     :return: A list of output variables which will be passed to next stage
    132     '''
--> 133     this_operator = scope.declare_local_operator(_get_sklearn_operator_name(type(model)), model)
    134     this_operator.inputs = inputs
    135 

/opt/conda/lib/python3.6/site-packages/skl2onnx/_parse.py in _get_sklearn_operator_name(model_type)
    118     '''
    119     if model_type not in sklearn_operator_name_map:
--> 120         raise ValueError("No proper operator name found for '%s'" % model_type)
    121     return sklearn_operator_name_map[model_type]
    122 

ValueError: No proper operator name found for '<class 'sklearn.pipeline.Pipeline'>'

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
xaduprecommented, Jan 18, 2019

Working on it right now.

0reactions
xaduprecommented, Jan 20, 2019

It should be fixed except one operator I could not convert but you can look the following unit test: https://github.com/xadupre/sklearn-onnx/blob/i26/tests/test_SklearnPipeline.py. ONNX does not implement an imputer on strings, see https://github.com/onnx/onnx/blob/master/docs/Operators-ml.md#ai.onnx.ml.Imputer.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Convert To Pipeline - Jenkins Plugins
This plugin converts Freestyle jobs to Pipeline jobs.
Read more >
Converting a Freestyle project to a Declarative Pipeline
The Declarative Pipeline Migration Assistant uses a best-effort approach during the conversion: supported configurations in Freestyle projects are automatically ...
Read more >
Converter pipeline - IBM
Converters convert data retrieved by crawlers into data that is suitable for indexing. Each converter can handle input that has its supported content...
Read more >
Is there a way how to convert Jenkins project into Pipeline?
I don't know a tool that converts existing project to pipeline project, so I guess you'd have to start from scratch. The documentation...
Read more >
Render Pipeline Converter | Universal RP - Unity - Manual
The Render Pipeline Converter converts assets made for a Built-in Render Pipeline project to assets compatible with URP.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found