onnx / onnx-tensorflow

Tensorflow Backend for ONNX
Other
1.27k stars 297 forks source link

Is sklearn -> onnx -> tensorflow supported? KeyError: 'ai.onnx.ml' #665

Open TheMichaelHu opened 4 years ago

TheMichaelHu commented 4 years ago

I wanted to see if this package played nicely with skl2onnx. Are these projects meant to be compatible, or do they use different sets of ops so the following behavior is expected?

  # train sklearn model
  x_train = np.array([[1., 1., 1.], [0., 1., 1.], [1., 0., 0.]])
  y_train = [1, 0, 1]
  sklearn_model = MLPClassifier().fit(x_train, y_train)

  # try to convert to tensorflow model via onnx
  signature = [('input', FloatTensorType([None, x_train.shape[1]]))]
  onnx_model = skl2onnx.convert_sklearn(sklearn_model, initial_types=signature)
  tf_model = onnx_tf.backend.prepare(onnx_model)

I get the following error when trying to do the sklearn -> onnx -> tensorflow conversion.

Traceback (most recent call last):
  File "savedmodel_save.py", line 56, in <module>
    main()
  File "savedmodel_save.py", line 41, in main
    tf_model = onnx_tf.backend.prepare(onnx_model)
  File "/path/iris/savedmodel/onnx-tensorflow/onnx_tf/backend.py", line 66, in prepare
    return cls.onnx_model_to_tensorflow_rep(model, strict)
  File "/path/iris/savedmodel/onnx-tensorflow/onnx_tf/backend.py", line 86, in onnx_model_to_tensorflow_rep
    return cls._onnx_graph_to_tensorflow_rep(model.graph, opset_import, strict)
  File "/path/iris/savedmodel/onnx-tensorflow/onnx_tf/backend.py", line 147, in _onnx_graph_to_tensorflow_rep
    strict=strict)
  File "/path/iris/savedmodel/onnx-tensorflow/onnx_tf/backend.py", line 247, in _onnx_node_to_tensorflow_op
    handler = handlers[node.domain].get(node.op_type, None)
KeyError: 'ai.onnx.ml'
chinhuang007 commented 4 years ago

Thanks for opening the issue. The onnx ml operators are currently not supported in onnx-tf converter. Can you try some models without ml operators? Your contribution is welcome too.

1025KB commented 4 years ago

Hi, Thanks!

Do you mean the onnx models converted from sklearn use ml operators?

chinhuang007 commented 4 years ago

Based on the error message, the model converted from sklearn includes ML operators.